The requirement is to fetch all active AD groups in a site collection using pnp powerhsell in SP 2013. We have tried querying the User Info list and also web.siteusers but have noticed that this fetches all users and AD groups including historical ones which are now deleted. These are not needed.

Is there any other way to achieve this? Server side code is not an option for us since we cant access the production servers.

1 Answer 1


Please try below PowerShell as administrator.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 $WebURL = "site collection URL"             
 $Web = Get-SPWeb $WebURL
 $ADGroupCollection= @()
 $ReportPath ="C:\ADGroups.csv"
     #Get all AD Groups from the site collection
     $ADGroups = Get-SPUser -Web $WebURL | Where { $_.IsDomainGroup -and $_.displayName -ne "NT AUTHORITY\authenticated users" -and $_.displayName -ne "Everyone" -and $_.Roles -ne "1" }
     #Iterate through each AD Group
     foreach($Group in $ADGroups)
             Write-host "Found AD Group:" $Group.DisplayName
             #Get Direct Permissions
             $Permissions = $Group.Roles | Where { $_.Name -ne "Limited Access" } | Select -ExpandProperty Name
             #Send Data to an object array
             $ADGroup = new-object psobject             
             $ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
             $ADGroup | add-member noteproperty -name "Permissions" -value ($Permissions -join ",")
             #Add to Array
     #Export Data to CSV
     $ADGroupCollection | export-csv $ReportPath -notypeinformation
     Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan


enter image description here

  • Thanks Emily. But server side code is not an option for us. We can only use client side scripts.
    – Avi
    Apr 1, 2021 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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