Hi @Vinod Survase ,
Your needs need to be divided into two parts of PowerShell to achieve:
- Use PowerShell to obtain the security group linked to each site collection in the tenant. But the prerequisite is that you need to have permissions on all site collections. Because it needs to traverse each site collection.
Here is the code:
#Parameters
$AdminCenterUrl = "https://tenant-admin.sharepoint.com"
$CSVPath = 'c:\Temp\ADGroupsInSPO.csv'
#Connect to SharePoint admin center
Connect-PnPOnline -Url $AdminCenterUrl -Interactive
#Get all SharePoint sites
$Sites = Get-PnPTenantSite
$Report = @()
#Loop through each site
ForEach ($Site in $Sites)
{
Try {
Write-host "Processing Site:"$Site.URL -f Yellow
Connect-PnPOnline -Url $Site.Url -Interactive
$ADGroups = Get-PnPUser | Where { $_.PrincipalType -eq "SecurityGroup" -and $_.Title -Notin ("Everyone","Everyone except external users", "Company Administrator", "SharePoint Service Administrator","All Users `(windows`)") }
ForEach ($Group in $ADGroups)
{
$Report += New-Object Pscustomobject -Property @{
SiteURL = $Site.URL
GroupName = $Group.Title
LoginName = $Group.LoginName
GroupEmail = $Group.Email
}
}
}
Catch {
continue;
}
}
$Report
#Generate a CSV file from the data
$Report | Export-Csv $CSVPath -NoTypeInformation
For more details, please refer to:
- For export of permission for all levels (site/list-library/folder/...), currently, in SharePoint, only site collection/site/list-library/folder/.. is supported for permission traversal. Instead of User/Group. As a workaround, you can export a CSV file and then filter and integrate the results.
For the code part, please refer to:
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.