Create Site collection using Powershell - Including Default groups

The below command is used to create a hosted Site collection under any web application using power-shell.



Add-PSSnapin "Microsoft.sharepoint.powershell"

$url = "Name of your Hosted Site collection"
$hostHeaderWA = "Name of your web application"
$SCollectionTitle = "Title of your site collection"
$SCollDescription = "Description of your site collection"

New-SPSite $url -HostHeaderWebApplication $hostHeaderWA `
                -Name $SCollectionTitle `
                -Description $SCollDescription `
                -OwnerAlias 'DomainName\AccountName' `
                -language 1033 `
                -Template 'STS#0'

The when you create your site collection (OR hosted site collection), you will see the default Owners/Members/Visitors groups are missing.
To create those groups, use the below Power-Shell command

$web = Get-SPWeb $url
$PrimaryLogin = $web.EnsureUser("DomainName\AccountName")
$web.CreateDefaultAssociatedGroups($PrimaryLogin,"","")

you can run the entire Power-Shell command together as well.



No comments:

Post a Comment