ExpertiseKnowledgeToolsField GuideBlogAbout
← pH7x KnowledgeSharePoint

How to detect a custom master page on a SharePoint site, correctly

Does this site use a master page other than the defaults?

By João Livio·pH7x Knowledge

30-second answer

powershell
$web = Get-PnPWeb -Includes MasterUrl, CustomMasterUrl
$file = Split-Path -Leaf $web.MasterUrl
$file -notin @('seattle.master', 'oslo.master')

Compare the file name, never the full path.

What this proves

Which master page file the site is configured to use, and whether it is one of the two SharePoint provides.

What it does not prove

  • That custom branding is in effect. Modern pages do not use the master page; a classic-era custom master can sit configured on a site whose users only ever see modern pages.
  • That CustomMasterUrl being set means anything by itself. It is set on every site, out of the box, pointing at the default. Its presence is not a customisation signal.

PowerShell

powershell
$web = Get-PnPWeb -Includes MasterUrl, CustomMasterUrl
[pscustomobject]@{
    MasterFile       = Split-Path -Leaf $web.MasterUrl
    CustomMasterFile = Split-Path -Leaf $web.CustomMasterUrl
}

Example output

text
MasterFile     CustomMasterFile
----------     ----------------
seattle.master seattle.master

Explanation

Two traps, both found on a real tenant. First, CustomMasterUrl is populated everywhere: a check for "is it set" fires on every site in the tenant. Second, the path carries the site: the root site reads /_catalogs/masterpage/seattle.master and /sites/finance reads /sites/finance/_catalogs/masterpage/seattle.master for the same default page. A rule comparing full paths against a known default reports every site that is not the root, which is most of them. The file name is the only part of the value that answers the question.

Production considerations

  • Load both properties with -Includes; unloaded CSOM properties return null, which reads as "no master page" if unguarded.
  • A file named neither seattle.master nor oslo.master is the real signal of classic branding effort, and classic branding is the part of a migration nobody can automate.

References