Real world experiences of SharePoint CSS engineers from Microsoft UK

Create a Site Structure using PowerShell

Create a Site Structure using PowerShell

  • Comments 3
  • Likes

Updated to reflect feedback from Wes MacDonald -

Another day, another excuse to write a PowerShell script! This time I was working with a customer who needed to create a Site Collection for their HR department with a large number of Sub-Sites (one for each team within the department), each Sub-Site required unique permissions. Rather than spending an hour doing this through the UI I put together a script to automate this.

Update the values highlighted and run, this will create a single Site Collection and a Sub-Site beneath for each of the department team names contained in text file referenced by the $Departments variable, it will remove any spaces from the names to ensure that the URL is valid and will use the original department name for the display name of the site. The parameters used to create the Site: New-SPSite and Sub-Site: New-SPWeb can be tweaked to match your particular requirements.

ASNP *SharePoint* -EA SilentlyContinue
$Owner = "CONTOSO\JohnDoe"
$WebAppURL = ""
$Departments= Get-Content "C:\Departments.txt"
$Site = New-SPSite ($WebAppURL + "Sites/" + "HR") -Template STS#0 -OwnerAlias $Owner
Foreach ($Department in $Departments) {$Web = New-SPWeb -Url (($Site.URL) + "/" + $Department.replace(" ","")) -Name $Department -Template STS#0 -UniquePermissions;$Web.CreateDefaultAssociatedGroups($Owner,$null,$Web.Title)}

Example $Departments input file:

Brendan Griffin


  • I noticed you specified -UniquePermissions you will also have to get the SPWeb object and execute something similar to the following (change the parameters as you see fit) to create the default security groups for the sub sites:

    $spWeb.CreateDefaultAssociatedGroups($spWeb.Site.Owner, $spWeb.Site.Owner, "");


  • Thanks, well spotted!

  • Well done

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment