What is the best method to get site collection IDs for all site collections including OneDrives?

Manoj Nisal 25 Reputation points
2024-02-14T15:29:35.87+00:00

I'm looking at ways to get sitecollectionID for all sites in an org.

  • Get-PnPTenantSite is a great cmdlet for enumeration of all sites. Unfortunately, it doesn't include site collection ID in the output.
  • Graph API is another option to enumerate all sites but it is limited to SharePoint Online site collections and doesn't include OneDrive enumeration.
  • Third option is to use CSOM query per site collection. However, this is not a performant approach as it can be very inefficient while dealing with thousand of site collections.

Is there any better approach than the ones mentioned above? It should handle enumeration of all SPO sites, OneDrives without having to connect to individual site collection. Thanks.

Microsoft 365 and Office | SharePoint | Development
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2024-02-15T09:00:32.6866667+00:00

    You could get all OneDrive site ID through Graph API.

    Here are steps:

    1.There is a hidden list called "DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGA" in the admin site. It stores a cached copy of aggregated site collections data from all contentDB. Get the ID of "DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGA" list.

    https://graph.microsoft.com/v1.0/sites/tenant-admin.sharepoint.com/lists

    1

    2.Get the TemplateId of OneDrive site.

    https://graph.microsoft.com/v1.0/sites/tenant-admin.sharepoint.com/lists/c30bb5e8-6a11-4387-832c-bb80d76dc48e/items?$expand=fields

    2

    3.Get all OneDrive sites.

    https://graph.microsoft.com/v1.0/sites/tenant-admin.sharepoint.com/lists/90403211-a51b-4a2b-8e83-a569011b63f7/items?$expand=fields&$filter=fields/TemplateId eq 21

    3


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sergii Bielskyi 75 Reputation points MVP
    2024-02-15T02:21:49.56+00:00

    You can use PowerShell command Get-SPSite to receive all site collection properties including ID. Take a look the article about this https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/get-spsite?view=sharepoint-server-ps


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.