0

I have a case where in I have added AD security groups along with SharePoint Users to the SharePoint Groups, Now I want to fetch a list of only Security Groups from all Site Groups in SharePoint, Is it possible through powershell or Console application.

0

This Script will get all the security groups listed in your groups at web level,similarly you can get if principal is Distribution list or a user or a Sharepoint Group

POWERSHELL

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
       Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
Write-Output "Starting process"
$outArray = @()
$websites = Get-SPWeb "http://site/*" 


foreach($web in $websites)
{
    $groups = $web.Groups

    foreach($grp in $groups)
    {
        $reachedMax= $false
        $principalInfo = [Microsoft.SharePoint.Utilities.SPUtility]::GetPrincipalsInGroup($web,$grp.Name,1000,[ref]$reachedMax)
        if($principalInfo.Count -gt 0)
        {
         foreach($info in $principalInfo)
         {
           if($info.PrincipalType -eq "SecurityGroup")
           {
              $outObject="" | select "Web","Group","SecurityGroup"
              $outObject.Web=  "Site Name and URL : " + $web.Title + " : " + $web.Url + ","
               $outObject.Group = $grp.Name+","
              $outObject.SecurityGroup += $outObject.SecurityGroup + " " + $info.DisplayName
               $outArray += $OutObject
              $outObject=$null
           }
         }     
       }
     }
 }
    $outArray | export-csv "c:\myFolder\FileName.csv"
Write-Output "finished process"
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.