Thursday, January 6, 2011

Creating predefined groups in site collection created by Powershell

Here's another discrepancy between what the UI does and what the Powershell scripts seem to do. As I'm in the process of scripting a manual creation process, one of the things I want to do is create a site collection. Looking at Technet you get instructions to Create a site collection (SharePoint Server 2010).

However, doing it via Central Administration vs via Powershell has a slight difference. If you create your site collection via the web UI you get a handful of SharePoint groups automatically created, but not if you create it via Powershell.

With the Powershell approach, there are "No predefined Groups in sitecollection created with Powershell". All you need to do is to call the CreateDefaultAssociatedGroups() method of the SPWeb object.

Here's the code I used:

New-SPSite -Url $sp_sc_url -Name $sp_sc_name -Template $sp_sc_template -OwnerAlias $sp_sc_owner -SecondaryOwnerAlias $sp_sc_owner2 -Language $sp_sc_language
$sp_web = Get-SPWeb $sp_sc_url
$sp_web.CreateDefaultAssociatedGroups($sp_sc_owner, $sp_sc_owner2, "")


No comments:

Post a Comment