Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > How to use PowerShell to set the Master Page in SharePoint 2010
August 29
How to use PowerShell to set the Master Page in SharePoint 2010

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

Comments

Setting master page inheritance

You'll have to set the value directly in the web's property bags, something like this:

http://www.kindohm.com/archive/2008/05/19/setting-sharepoint-web-master-pages-programmatically.aspx
 on 8/29/2010 1:00 PM

Todd Klindt Developper

Conclusion

So what's the big deal here? LightSwitch allows you to very easy and fast create an application (using this even Todd Klindt can call himself a developer).

source:
http://www.wictorwilen.se/Post/How-to-create-a-SharePoint-2010-application-using-Visual-Studio-2010-LightSwitch.aspx

:D
 on 9/4/2010 12:39 PM

Managed Paths

And if you have a site collection under a managed path like "sites"
$web.CustomMasterUrl = "/sites/SITECOLLECTION/_catalogs/masterpage/nightandday.master"
$web.MasterUrl = "/sites/SITECOLLECTION/_catalogs/masterpage/nightandday.master"
 on 10/10/2012 10:24 PM

Disable the option to change site Master page

I got a peculiar requirement to hide/remove the option of changing the site master page when publishing feature enabled. Client wants to maintain consistent look and feel across the web application. So is there a way to restrict users from changing the Master page.(Yes, i know deactivating the publishing feature will remove this menu from the look and feel section, but we do not want to deactivate this feature and it is heavily used).
 on 1/3/2013 7:37 AM

Re: Disable the option to change site Master page

If I were trying to do this, I'd start with creating a custom Permission Level that does not have permission to change Master Pages. Don't alter an out of the box one, copy an existing one and edit that.

tk
Todd O. KlindtNo presence information on 1/3/2013 11:20 AM

Re: Disable the option to change site Master page

Thanks for the prompt reply.
Could you please let me know the permission name that will restrict the user from changing the master. I can see permission to restrict users from changing the theme and CSS but not for Master pages.

Thanks
Arun
 on 1/7/2013 11:57 AM

Re: Disable the option to change site Master page

Thanks for the prompt reply.
Could you please let me know the permission name that will restrict the user from changing the master. I can see permission to restrict users from changing the theme and CSS but not for Master pages.

Thanks
Arun
 on 1/7/2013 12:11 PM

Re: Disable the option to change site Master page 

Thanks Todd. I created new permission level and restricted users from changing the Master page
 on 1/10/2013 10:00 AM

Re: Disable the option to change site Master page 

Thanks Todd. I created new permission level and restricted users from changing the Master page
 on 1/10/2013 10:00 AM

Does this work where the publishing feature is not enabled?

Thanks Todd. I ran this and it worked fine for changing the site Master Page. The sysytem pages master page did not change though. I do not have the publishing feature enabled on the sites I ran this on.
 on 5/14/2013 6:09 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit