Find all groups in Site Collection using a specific permission level

Find all groups in Site Collection using a specific permission level. Helpful for removing outdated custom permission levels.

$siteUrl = "https://WEBAPP/sites/SITECOLLECTION"
$permission = "Restricted Read"
function Get-SPGroupByPermissionLevel([string]$url, [string]$permLevel) {
$spWeb = Get-SPWeb $url
$spGroupCollection = $spWeb.SiteGroups;
$group = $spGroupCollection | ? {$_.Roles | ? {$_.Name -eq $permLevel} }
$spWeb.Dispose()
return $group;
}
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl);
$spWebApp = $rootSite.WebApplication;
foreach($SPSite in $spWebApp.Sites)
{
$siteURL = $SPSite.URL;
Write-Host "SITEURL: $siteURL"
        $groups = Get-SPGroupByPermissionLevel $siteURL $permission;
        foreach($group in $groups)
        {
if($group -ne $NULL){
Write-Host "-Web "$siteURL "-Group "$group
}
}
$SPSite.Dispose();
}
$rootSite.Dispose();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: