0

I have SharePoint 2013 sites. I want to export all the security group in Csv file. I want the security group name and the principle type of the group. Also, it is located in site level or subsite level needs to add in the CSV file. Someone please help me with this.

1 Answer 1

0

Please run below PowerShell as administrator.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
 #Change to your web application
 $WebAppURL = "web application URL"
     
 #Get Web Application
 $WebApp = Get-SPWebApplication $WebAppURL
     
 #variable for data collection
 $ADGroupCollection= @()
 $ReportPath ="C:\ADGroups.csv"
     
 foreach ($Site in $WebApp.Sites)
 {
     Write-host -foregroundcolor green "Processing Site Collection: "$site.RootWeb.URL
         
     #Get all AD Security Groups from the site collection
     $ADGroups = Get-SPUser -Web $Site.Url -Limit ALL | Where { $_.IsDomainGroup -and $_.displayName -ne "NT AUTHORITY\authenticated users" -and $_.displayName -ne "Everyone" -and $_.displayName -ne "All Users (windows)"}
     
     #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
     
             #Get SharePoint User Groups where the AD group is a member
             $SiteGroups = $Group.Groups | Select -ExpandProperty Name
     
             #Send Data to an object array
             $ADGroup = new-object psobject
             $ADGroup | add-member noteproperty -name "Site Collection" -value $Site.RootWeb.Title
             $ADGroup | add-member noteproperty -name "URL" -value $Site.Url
             $ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
             $ADGroup | add-member noteproperty -name "Direct Permissions" -value ($Permissions -join ",")
             $ADGroup | add-member noteproperty -name "SharePoint Groups" -value ($SiteGroups -join ",")
             #Add to Array
             $ADGroupCollection+=$ADGroup          
     } 
 }
     #Export Data to CSV
     $ADGroupCollection | export-csv $ReportPath -notypeinformation
     Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan

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.