Thursday, June 30, 2011

Creating SP 2010 Sites using PowerShell

We all know PowerShell is recommended command line tool for SharePoint 2010. But PowerShell does not support the same style as the UI supports.
I ran in to problem, when I was creating sites using PowerShell. After creating sites I was not able to see the default groups (Members, Visitors and Owners) for the site. But when you create site from UI, you have all those available.
I figured out that, we need to execute one more command in order to get that. The steps can be as listed below:
1. Create Site, either using New-SPSite or simple .NET style code to add site to web application $WebApp.Sites.Add(params....).
2. After that execute command as :
$CurrentWeb.CreateDefaultAssociatedGroups($PrimaryOwnerLogin,
$SecondaryOwnerLogin,
$CurrentWebTitle)

It will create the groups with the current site title for e.g. MyProjects Members.

No comments: