Creating SharePoint default permission groups PowerShell

In SharePoint 2013 by rhodzyLeave a Comment

If you have created a hostname site collection via PowerShell you may have noticed that the default user groups “Site Owners, Site Visitors, Site Members” aren’t actually there. This is because when the site is created with PowerShell these groups aren’t actually created.

To do this, we need to go to PowerShell ISE to create the groups on the site.

Add-PSSnapin Microsoft.SharePoint.PowerShell

$web = Get-SPWeb http://CHANGEME

if ($web.AssociatedVisitorGroup -eq $null) {

Write-Host ‘The Visitor Group does not exist. It will be created…’ -ForegroundColor DarkYellow

$currentLogin = $web.CurrentUser.LoginName

if ($web.CurrentUser.IsSiteAdmin -eq $false){

Write-Host (‘The user ‘+$currentLogin+’ needs to be a SiteCollection administrator, to create the default groups.’) -ForegroundColor Red

return

}

$web.CreateDefaultAssociatedGroups($currentLogin, $currentLogin, [System.String].Empty)

Write-Host ‘The default Groups have been created.’ -ForegroundColor Green

} else {

Write-Host ‘The Visitor Group already exists.’ -ForegroundColor Green

}

When you go back to your site now, you should notice that the groups have been created.