Create site with approval workflow using PowerShell Part 2
This is the fourth Cross Blog post that I’ve made with Mattias and they are getting better and better.
Now, we are heading onto MOSS and the SiteDirectory. Scripting the SiteDirectory is basically the same as scripting a list with items. The fun part is checking the “Approved” value set by an administrator or by someone with the right credentials. The Approved Status can be set to: Approved, Rejected or Pending (default). In PowerShell, the values will be 0, 1, 2 (default). so if we want to check for items that are approved, we check for items that equal 0.
I’ve included a couple of if else statements that check if the Site is Approved, if the New Site already exists, If the Parent Site Url is valid and so on. An example is if you approve a site that has the following Url:
http://Sharepoint/SiteThatDoesnExist/SiteToCreate
The script won’t create the Site since it’s parent doesn’t exist and will instead prompt you with a recommendation to either create the Parent Site or change the item value. Script Parameters:- -Url Url to SharePoint (Required)
- -Web Relative Url to SiteDirectory (Required)
- -List List containing information regarding Sites (Required)
- -Template Template to use when creating New Sites (Required)
- -help Prints the HelpFile (Optional) If you are unsure of whitch Template to use, you can always run the following function to find out which templates are available on your SharePoint Server:
function Get-Templates([string]`$Url) {
$SPSite = New-Object Microsoft.SharePoint.SPSite($Url)
$SPSite.GetWebTemplates(1033) | Select Name, Description
$SPSite.Dispose()
}
PS > Get-Templates http://SharePoint
Now with the basic script procedure in place, we can start Approving sites and scripting them into SharePoint. Start by Approving a Site.
Now if we check out the Sites list, the Item will be Approved.
Next, start up PowerShell and trigger the script. Change the Arguments to fit your environment. Run the script.
And if you check the Url specified in the Item thats Approved, the New Site will have been created.
Here’s an example on running the script:
PS > .\Check-SiteDirectory.ps1 -Url http://makanigo -Web SiteDirectory -List Sites -Template STS#0 PS > .\Check-SiteDirectory.ps1 -helpClick here to Download the Script
[?]

I can tell that this is not the first time at all that you mention the topic. Why have you decided to write about it again?