If you need to get SharePoint security group details for all the SharePoint online site collections then you might to use a 3rd party tool to generate that report for you. This could also be possible by going through all the sites or using PowerShell.

I am sharing a simple PowerShell where you can share the list of all site collections in a csv file and script will loop through all the site collections and will list you all the site security groups used in that site collection.

$TenantUrl = "https://<site URL>-admin.sharepoint.us"
$CSVPath = "D:\Migratedsites.csv"

Connect-SPOService -Url $TenantUrl

$SiteCollections = Import-Csv -Path $CSVPath
 
    #Loop through csv and create site collections from each row
    ForEach ($Site in $SiteCollections)
    {
        $siteUrl = $Site.URL
        Write-host "Creating Site Collection:" $siteUrl -f Yellow
        $group = Get-SPOSiteGroup -site $siteUrl | Select Title, Roles, Users  | Where-Object {$_.Roles -eq "Edit"}
        
  } 

Now you can use this script for multiple purpose, can add user to and of the security group, or can fetching the member details for any of these security groups. You can add below cmdline to add a user to the group:

Add-SPOUser -Site $siteUrl -Group $group.Title -LoginName $UserAccount

You can also filter the groups by role by adding a filter to the Get-SPOSiteGroup function:

  Get-SPOSiteGroup -site $siteUrl | Select Title, Roles, Users  | Where-Object {$_.Roles -eq "Edit"}

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply