How To Change SharePoint SubSite Master Page Using PowerShell

This article provides the PowerShell script to change the master page of a subsite.

Background

I recently was working on a master page customization where I had to hide the page until the page was completely loaded, so as to avoid page flickering. However, during the process, I lost complete access to the site as all the pages got hidden and I had no way of resetting the master page from the user interface. That’s when PowerShell came to my rescue.

PowerShell Script

## Get Subsite Instance
$spWeb = Get-SPWeb “<SiteUrl>”

## MasterUrl for all pages and forms
$spWeb.MasterUrl = “/sites/sitecollection/_catalogs/masterpage/seattle.master”

## CustomMasterUrl for all publishing pages
$spWeb.CustomMasterUrl = “/sites/sitecollection/_catalogs/masterpage/seattle.master”
$spWeb.Update()

Conclusion

PowerShell provides an easy way to revert the master pages of subsites. With small modifications, this method can be used to reset the master pages of multiple sites. The same web properties can be used in CSOM as well.