The master page setting is scoped at the web level, so the first thing I did was use Get-SPWeb to get a variable for the web I want to change. There are two properties that control the master page settings; MasterUrl and CustomMasterUrl. The former controls the master page used to render the System pages (the ones that start with /_layouts) and the latter controls the master page used to render the content pages. This picture helps explain it better:
To alter those settings for a publishing site at http://sharepoint, use the following PowerShell script:
$web = Get-SPWeb http://sharepoint
$web.CustomMasterUrl = “/_catalogs/masterpage/nightandday.master”
$web.MasterUrl = “/_catalogs/masterpage/nightandday.master”
This changes the master page for both settings and content to nightandday.master. Since we’re doing this with PowerShell it’s easy to loop through a group of webs and set their master pages to whatever you like. I haven’t found a way in PowerShell to set the “inherent system master page from parent” property for a web. If anyone knows how to do that, drop me a line.
Happy Coding !!