I'd like to know if there was a way to run a master page audit on all the sites in my collection

Is there a powershell script I can run or some OOTB feature I can run that will tell me this information.

I know how to look into the look and feel then master pages but I'd like to run a report on all my sites to find out which ones are using which.


You did not state if you are using SharePoint Online or Premise so I created this quick script for an on-premise environment. You will need to run it as a farm account, or as a account that has access to all content databases.

It loops through all the webapplications (excluding central admin for obvious reasons) and then every sitecollection in each webapp, finds the rootsite and check the properties for the sites Master page URL and if there is any custom CSS applied. Exports everything out to a CSV file on your local hard-drive.

Add-PSSnapin Microsoft.SharePoint.PowerShell

$webApplications = Get-SPWebApplication -IncludeCentralAdministration:$false

foreach ($webApp in $webApplications) {

    foreach($site in $webApp.Sites) {

        $web = $site.RootWeb
        $Url = $web.Url
        $customMasterUrl = $web.CustomMasterUrl
        $masterUrl = $web.MasterUrl
        $alternateCssUrl = $web.AlternateCssUrl

        New-Object -TypeName PSCustomObject -Property @{
        Url = $Url
        customMasterUrl = $customMasterUrl
        masterUrl = $masterUrl 
        alternateCssUrl = $alternateCssUrl
        } | Select-Object Url, customMasterUrl, masterUrl, alternateCssUrl | Sort-Object Url | Export-Csv -NoTypeInformation -Append -Delimiter ";" -Path C:\masterpages.csv


As this is for SharePoint Online and I can't test it as I do not have any active tentants to test at for the moment, this is somewhat psuedo-code that might work, using the PNP-PowerShell module to connect to your tenant and then try to get the same information as for on-premise.

Using PNP, you connect to a single site, not a collection so this script would require you to type your credentials for every site you have if you don't configure your credentials as stated in the link below. However I think that there is some smarter way to get the information from an SharePoint Online tenant.

How to use the Windows Credential Manager to ease authentication with PnP PowerShell

This does require that you first install the module, but I recommend it. It's a game-changer and a lifesaver.


if(!(Get-Module -Name PnpDevice)) { Import-Module *pnp* }

Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)

$sites = Get-PnPTenantSite

foreach ($site in $sites.Url) {
    Connect-PnPOnline -Url $site.Url -Credentials (Get-Credential)
    Get-PnPMasterPage | Export-Csv -NoTypeInformation -Append -Delimiter ";" -Path C:\masterpages.csv
    Disconnect-PnPOnline -Url $site.Url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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