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

1 Answer 1


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
  • Thank you for this. It's helped a lot. But is there a way to get it to keep drilling down on each sub-site?
    – Mile T.
    May 29, 2018 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.