Request a 60-minute free consultation

Get all SharePoint groups on a SharePoint Online Site

To retrieve all SharePoint groups within a SharePoint Online site. Here's a PowerShell script to accomplish this:


# Define the SharePoint Online site URL
$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSiteName" # Replace with your site's URL

# Connect to SharePoint Online
Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com"

# Connect to the SharePoint site
Connect-PnPOnline -Url $siteUrl -UseWebLogin

# Get all SharePoint groups in the site
$groups = Get-PnPTenantSite | ForEach-Object { Get-PnPTenantSiteTemplate $_.TemplateId } | Where-Object { $_.Type -eq "List" -or $_.Type -eq "Document Library" } | Get-PnPTenantList | ForEach-Object {
    $list = $_
    Get-PnPTenantGroup -List $list
}

# Display the group names
foreach ($group in $groups) {
    Write-Host "Group Name: $($group.Title)"
    Write-Host "Group ID: $($group.Id)"
    Write-Host "------------------------"
}

# Disconnect from SharePoint Online
Disconnect-PnPOnline

# Disconnect from SharePoint Online Management Shell
Disconnect-SPOService


Instructions:

Replace the following placeholders in the script with your specific information:

  • https://yourtenant.sharepoint.com/sites/YourSiteName: Replace with the URL of the SharePoint site from which you want to retrieve groups.

After updating the script with your information, save it as a .ps1 file and run it using PowerShell. This script will connect to your SharePoint Online site, retrieve all SharePoint groups within the site, and display their names and IDs.

Ensure you have the necessary permissions to access the site and retrieve group information.

Other solutions

Connect with HarjGroup

Contact Us
Find out how HarjGroup's expertise can help you and your company.