Forum Discussion
nabin pokharel
Feb 13, 2019Copper Contributor
Getting the List of all sites/ sub-sites and their owners using PnP
Hi,
I am trying to get the list of all the SharePoint sites/ sub-sites that I have access to in my tenant in SharePoint Online. Also I have to make a list of all the sites/ sub-sites with their Owners. What is the best way to achieve this?
If script is needed, PnP is preferred.
I am trying to achieve this using PnP but haven't figured out yet. Here's what I have done:
1. Get list of all sites in the tenant :
Get-pnptenantsite
2. For each site collection, find the list of sites and subsites:
get-pnpsubwebs -recurse
3a. I don't know how to get the list of users in each subsite. I tried
get-pnpusers
, but it is giving the users at top level site collection not sub-sites.
3b. I can find the site admin using IsAdmin is true, but can't find the Owners (both individuals and group)
Thanks,
Nabin
- OfficeKundigCopper ContributorHowever there are subsites available I am not able to call these using the commands above.
No Subsites detected.
I just updated the online pnp powershell but had no positive affect.
Please inform me how to check if there are subsites and which using PnP Powershell - Anders Brunholm SylvestBrass Contributor
Hi,
Using SPO Pnp PowerShell, you should be able to get a list of web users, after iteration webs using this:
https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpuser?view=sharepoint-ps
Iterate through "get-pnpsubwebs -recurse" and then call "Get-PnpUser" for each web.
- juanfilettiCopper ContributorGood
- Naveen KarlaIron Contributor
Did you try using Search webpart or Search REST API
You can use search with either the Search Web Parts or using REST for search.
Search WebPart:
Find all Site Collections: “contentclass=STS_Site”
Find all Webs (top level sites and subsites): “contentclass=STS_Web”http://techtrainingnotes.blogspot.com/2015/07/using-sharepoint-serach-to-find-sites.html
Search REST API:
http://yourserver/sites/yoursite/_api/search/query?querytext='contentclass=STS_Site'
http://yourserver/sites/yoursite/_api/search/query?querytext='contentclass=STS_Web'https://msdn.microsoft.com/en-us/library/office/jj163876.aspx
You could also use Graph API to get these details
Owner for each site can be fetched using
https://graph.microsoft.com/beta/sites/{site-id}?$select=*,drive&$expand=drive
- nabin pokharelCopper Contributor
Thanks Naveen Karla ,
I haven't approached through Search or REST API or Graph API. I will give it a shot.
-Nabin