SOLVED

Can i get a list of all site collections in a tenant using power automate?

Iron Contributor

Hi All,

Will it be possible to get  a list of all site collections in a tenant using power automate?
Currently I'm using powershell and have to query the sharepoint admin site.

But i'm thinking power automate can do similar?

 

Thanks 

18 Replies

Any updates from any one from Microsoft?

 

Hi @Patrick Rote ,

 

In case you haven't already figured this out... Yes, you can use the "Invoke an HTTP request (Azure AD)" to issue a Graph query to get all sites. See the Graph documentation for an example to test in Graph Explorer with your credentials. 

Then Parse JSON to get at the individual fields, and then do whatever you wanted to do. In the example below, I'm just displaying them in an HTML table which could then be emailed or whatever.

 

[Sorry, image attached - I couldn't embed it for some reason.]

Does this help you...?

 

Sandy

@Patrick Rote 

In SharePoint admin center site, there is one list with name "DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS" which contains the list of all site collections in tenant.

 

So, you can call SharePoint REST APIs using "Send an HTTP request to SharePoint" action in Power Automate to fetch the items from above list which will have details about site collections.

 

ReferenceGet All Site Collections Of Office 365 Tenant In MS Flow 


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

 

@Sandy Ussia 

 

The query you mentioned in your answer will return all the sites (and subsites) and not only site collections in tenant.

 


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

 

@Sandy Ussia Would you be so kind as to detail the Parse Jason section please?

 

Thanks!

 

Jane

@JeanneDarche 

Sure! 

Here's a screenshot of the Parse JSON action:

SandyUssia_0-1689212921447.png

Body is from the Invoke HTTP Request action.

The Schema is based on that HTTP request (https://graph.microsoft.com/v1.0/sites?search=*) from the Microsoft Graph. My flow is nearly 3 years old at this point, so the content returned by that request might be a little different now. I would recommend using the Generate from sample button in the Parse JSON action to paste in sample JSON from that HTTP request. You could perform the request in the Graph Explorer to make sure you're getting what you expect, and then paste that into the "Sample" box in Power Automate to generate the schema.

I hope this helps!

Sandy

I tried with the SharePoint rest api, but the GET only returns 100 results. I have a few hundreds sites. Does using Microsoft Graph works around this problem?
best response confirmed by Sandy Ussia (MVP)
Solution

@JeanneDarche Are you using Send HTTP Request to SharePoint action? what is the the Uri/endpoint you are using?

 

Usually, you can add &$top=5000 at the end of REST API endpoint to get more than 100 items.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

This is a cool method; I wasn't aware of that hidden list of site collections that you can get to without a premium Power Automate license. I've tested this (including the $top parameter to remove the 100 limit), and it works great - thanks, Ganesh!

@ganeshsanap This is the Uri.  How do I add &$top=5000 ?   Thanks in advance!

 

Power Automate http request.png

 

 

 

@JeanneDarche You can add ?$top=5000 after /items like: 

 

_api/web/lists/getbytitle('DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS')/items?$top=5000

 


Please consider giving a Like if my post helped you in any way.

It worked!

Thanks so much for your help!

Jeanne

Hi @ganeshsanap

I am also doing the same task here, but i am doing from SPFX webpart

I can able to get any other lists or site contents , but not the because it through 403 status error

https://url-admin.sharepoint.com/_api/web/lists/GetByTitle('DO_NOT_DELETE_SPLIST_TENANTADMIN_AGGREGATED_SITECOLLECTIONS')

Muralikrishna1845_0-1690536937945.png

 

Note: if I access the above URL in Browser then I can get response and required data.

Muralikrishna1845_1-1690537112033.png

Please help me how can i access the Site/Web sites list from tenant.
Actually I have Tenant admin permission. 

but still it shows 403 error

Hi @ganeshsanap,
I have already used the sharePoint search , please correct me if this is the way to get using SharePoint search please open the below link

https://stackoverflow.com/questions/76720491/how-to-get-all-the-site-collections-webs-from-tenant-si...
Please help with your assistance me here or there

@ganeshsanap would you be able to help in how to get sites more than 5000? We may have more than 20k sites 

1 best response

Accepted Solutions
best response confirmed by Sandy Ussia (MVP)
Solution

@JeanneDarche Are you using Send HTTP Request to SharePoint action? what is the the Uri/endpoint you are using?

 

Usually, you can add &$top=5000 at the end of REST API endpoint to get more than 100 items.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

View solution in original post