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 the 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 a PowerShell example 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 to Get Group
Use the Get-SPOSiteGroup cmdlet with the 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
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
Does $Group.Roles return value ?
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?
Open the CSV file in Microsoft excel.