A couple of months ago Randy Drisgill asked me if there was a way to use the mighty PowerShell to set a web's master page in SharePoint 2010. Not being a branding guy I hadn't tried it before. Heck, I'm not even sure what a master page is, but for Randy I dug into it.
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"
$web.Update()
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.
Hope this helps,
tk