SharePoint Online: PowerShell to Get All SharePoint Groups

Requirement: SharePoint Online PowerShell to List All Groups in a Site Collection

Get SharePoint Online Groups using PowerShell: Get-SPOSiteGroup

The Get-SPOSiteGroup PowerShell cmdlet displays a list of all existing SharePoint groups for a specific site collection. Use SharePoint Online Management Shell console to get user groups in SharePoint Online.

Get-SPOSiteGroup -Site <Site-Collection-URL>

This PowerShell cmdlet gets you all SharePoint groups, permission levels, and users in a site collection. You can get the permission level(s) associated with each group in the site collection by accessing the Roles property of a group.

SharePoint Online PowerShell to List All Groups

Here is an example PowerShell to get all groups from a SharePoint Online site:

#Admin Center URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get All Groups of a site collection
Get-SPOSiteGroup -Site "https://Crescent.sharepoint.com/sites/marketing"

Let’s get all Groups, Group permissions, and group users

#Get Group Name, Role and Users
Get-SPOSiteGroup -site https://Crescent.sharepoint.com/sites/marketing | Select Title, Roles, Users
sharepoint online powershell list all groups

SharePoint Online: PowerShell to Get Group

Use Get-SPOSiteGroup cmdlet with Group parameter to get a group in SharePoint Online site.

Get-SPOSiteGroup -Site "https://Crescent.sharepoint.com/sites/marketing" -Group "Marketing Owners"

Export SharePoint Online Groups Data to CSV:

Let’s get all groups from a SharePoint Online site and export the group’s data to a CSV file.

#Admin Center & Site collection URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\Groups.csv"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get All Groups of a site collection
$Groups = Get-SPOSiteGroup -Site $SiteURL
Write-host "Total Number of Groups Found:"$Groups.Count

$GroupsData = @()
ForEach($Group in $Groups)
{
    $GroupsData += New-Object PSObject -Property @{
        'Group Name' = $Group.Title
        'Permissions' = $Group.Roles -join ","
        'Users' =  $Group.Users -join ","
    }
}
#Export the data to CSV
$GroupsData | Export-Csv $CSVPath -NoTypeInformation 

SharePoint Online PnP PowerShell to Get Groups

You can get all groups from a SharePoint Online site with the cmdlet Get-PnPGroup. Here is the PnP PowerShell to list SharePoint Online groups from the given site:

#Site collection URL
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
 
#Connect to SharePoint Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get All Groups from the site - Exclude Hidden, Limited Access and SharingLinks Groups
Get-PnPGroup | Where {$_.IsHiddenInUI -eq $false -and $_.LoginName -notlike "Limited Access*" -and $_.LoginName -notlike "SharingLinks*"}

You can also use the Get-PnPSiteGroup cmdlet that offers some additional group data!

#Site collection URL
$SiteURL= "https://Crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\GroupData.csv"
 
#Connect to SharePoint Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get All Groups from the site - Exclude Hidden, Limited Access and SharingLinks Groups
$Groups = Get-PnPSiteGroup | Where { $_.LoginName -notlike "Limited Access*" -and $_.LoginName -notlike "SharingLinks*"}

$GroupsData = @()
ForEach($Group in $Groups)
{
    $GroupsData += New-Object PSObject -Property @{
        'Group Name' = $Group.Title
        'Permissions' = $Group.Roles -join ","
        'Users' =  $Group.Users -join ","
    }
}
#Export the data to CSV
$GroupsData | Export-Csv $CSVPath -NoTypeInformation 

Here is another post to get SharePoint Online groups from all site collections: SharePoint Online: Site Users and Groups Report using PowerShell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

4 thoughts on “SharePoint Online: PowerShell to Get All SharePoint Groups

  • my organization having 1000 subsites i want see selected subsites groups
    1 generate report list of groups available in subsites
    2 create groups in subsites
    3. delete groups in subsite

    Reply
  • thanks – great script – question though, when i get the results via csv, its not displaying this data,. if out put to a txt file, it does show the data, but not in a very readable format.. Any ideas?

    Reply

Leave a Reply

Your email address will not be published.