Question

All I'm trying to do is scan a site collection and have it return which masterpages are being used for all my sites, sub-sites and pages in a SharePoint online environment.

Any suggestions would be very welcome. Because this is for SharePoint online I can use regular SPO commands and I have also loaded PnP on to the management shell.

I'm aware of Get-SPOSite and found a page here that builds a SPOWeb object

I'm pretty new to Powershell so any help would be great.

Basically the script would iterate through each site and page in the collection and tell me which master page is used in each

Was it helpful?

Solution

Each site has its own copy of a master page, and each could have been customized. The following will just return the name of the master page (such as Seattle.master) as part of a URL to the page.

Using the PNP cmdlets: (the URL is for the top level site in the site collection)

Connect-PnPOnline https://yourDomain.sharepoint.com/sites/yourSiteCollection

# for the top level site
Get-PnPWeb -Includes masterurl | 
  select url, masterurl

# for each subsite
Get-PnPWeb -Includes masterurl, webs | 
  select -ExpandProperty webs | 
  Get-PnPWeb -Includes masterurl | 
  select url, masterurl
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top