Thursday, 11 June 2015

Powershell: Apply permission to existing groups in a site collection powershell

$site = Get-SPSite http://alenalstage.tawazun.ae/
$perLevel = "Read"
$groups = $site.RootWeb.sitegroups

foreach ($grp in $groups)
{
$groupName = $grp.name
Write-Host "Group: " + $groupName


    $assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($grp)
    $role = $site.RootWeb.RoleDefinitions[$perLevel]
    $assignment.RoleDefinitionBindings.Add($role)
    $site.RootWeb.RoleAssignments.Add($assignment)


}

$site.Dispose()

No comments:

Post a Comment