Get All Microsoft 365 Group Connected SharePoint Sites using PowerShell

Recently, I was building an SPFx webpart that displays the tasks assigned to the current user in Microsoft Planner. Since Microsoft Planner is always linked to group-connected SharePoint sites, I was required to obtain the groupId.

In this article, I will explain how to retrieve all Microsoft 365 group connected SharePoint sites with their Group IDs using PnP PowerShell and the SharePoint Online Management Shell.

Get Group-Connected SharePoint Site Group ID using PnP PowerShell

Here, we’ll learn how to get all the Microsoft 365 group-connected SharePoint sites‘ URL, Title, and Group ID into an Excel file. As shown in the image below, please enter the code below in Visual Studio and run it.

get group connected sharepoint site group id using powershell
$AdminCenterURL = "https://<tenantname>-admin.sharepoint.com/"
#Connect to SharePoint Online
Connect-PnPOnline -url $AdminCenterURL -Interactive -ClientId "Your Client ID"
Get-PnPTenantSite -GroupIdDefined $true | Select URL, Title, GroupId | Export-Csv -Path "D:\TEMP\GroupConnectedSites.csv" -NoTypeInformation
Disconnect-PnPOnline

Here:

  • $AdminCenterURL = Provide your SharePoint admin centre URL.
  • Connect-PnPOnline = This command is used to interact with the SharePoint admin centre using PnP PowerShell.
    • -url = Provide admin centre URL.
    • -Interactive = This will ask for your credentials while the code is running.
    • -ClientId = Provide your client ID created in Microsoft Entra ID.
  • Get-PnPTenantSite = This PnP PowerShell command retrieves the site collection information through the SharePoint Online tenant site.
    • -GroupIdDefined $true = This will retrieve only the sites that are group-connected.
    • Select URL, Title, GroupId = This will only retrieve the URL, Title, and Group ID of those sites.
  • Export-Csv -Path = This command is used to create an Excel with the output data.
  • Disconnect-PnPOnline = To disconnect our connection to the SharePoint admin centre once the code runs successfully.

Look at the image below. Once the code runs successfully, I retrieved the details of the group-connected SharePoint sites in an Excel file.

get group connected sharepoint sites using powershell

Get Group-Connected SharePoint Site Group ID using SharePoint Online Management Shell [SPO]

As in the above example, we will also see how to retrieve all group-connected SharePoint sites, along with their corresponding group IDs, into an Excel file using the SharePoint Online Management Shell.

  1. Provide the code below in the Windows PowerShell ISE or other platforms where this SPO is supported. Then, run the code. In the terminal pane, you will also see the table format of the output.
How to get all SharePoint group connected sites group ids
Connect-SPOService -Url "https://<tenant name>-admin.sharepoint.com"
$sites = Get-SPOSite -Limit All
$results = foreach ($site in $sites) {
    [PSCustomObject]@{
        SiteUrl   = $site.Url
        Connected = if ($site.GroupId -and $site.GroupId -ne [Guid]::Empty) { "Yes" } else { "No" }
        GroupId   = if ($site.GroupId -and $site.GroupId -ne [Guid]::Empty) { $site.GroupId } else { $null }
    }
}

$results | Format-Table -AutoSize
$results | Export-Csv -Path "D:\TEMP\SiteGroupConnections.csv" -NoTypeInformation

Here:

  • Connect-SPOService = This command is used to interact with the SharePoint admin centre using SharePoint Online Management Shell.
  • Get-SPOSite -Limit All. It retrieves all sites present in the SharePoint tenant admin centre and stores them in the $sites variable.
  • foreach (.){…}= This foreach loop is iterating on $sites and checks if each site is group-connected or not. If yes, retrieve the group ID and display it as “Yes” in the connected column; otherwise, display “No.” This output is stored in the $results variable.
  • Export-Csv = Using this command, we create an Excel file with the above results.
  1. Once the code runs successfully, please check the folder mentioned in the code; you will find an Excel file containing the results mentioned above.
list all microsoft 365 group connected sharepoint sites

This way, you can easily obtain the group IDs of group-connected SharePoint sites into an Excel file using PowerShell commands.

I hope you find this article helpful!, In this article, I have explained two different approaches to list all Microsoft 365 group-connected SharePoint sites using PowerShell, along with their corresponding group IDs. Follow this article if you are also looking to get SharePoint sites’ Group IDs programmatically.

Also, you may like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…