0

I'm working on a **sharepoint foundation 2013.**I have applied a custom masterpage on the root site the site collection.I would like all the subsites to inherit this masterpage and apply across all aistes. How can i get this done using powershell as i don't want to have to do it individually.

Thanks in Advance

  • you want to update master page in your site collection and there sites I have update my code in my answer second snippet code will work for you I have test it it work for me Let me know if you find any issue Thanks – S.P Mar 4 '16 at 5:03
1
$url = "http://sitecollectionrootUrl"    
$site = Get-SPSite $url    
foreach ($web in $site.AllWebs)
{   ##I have commented out the system master Url setting
    ##$web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "/_catalogs/masterpage/Mycustom.master";
    $web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/Mycustom.master";    
    $web.Update();    
    $web.Dispose();    
}
$site.Dispose();
1

For All Site Collection in your webapplication

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    #Get All site collections
    $SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All
    #Loop through all site collections
       foreach($Site in $SiteCollections)
        {
            #Loop throuh all Sub Sites
           foreach($Web in $Site.AllWebs)
           {
$web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "/_catalogs/masterpage/oslo.master";
$web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/oslo.master";
$web.Update();
Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;
           }
        }

Particular Site Collection

$site = Get-SPSite http://sp:1000/sites/Ex15
foreach ($web in $site.AllWebs)
{
    $web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "/_catalogs/masterpage/oslo.master";
    $web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/oslo.master";
    $web.Update();
    Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;
}
$site.Dispose()
0

You would want to loop through all the subsites and then set the value of the masterpage for each with the following code.

$web = Get-SPWeb http://sharepoint

$web.CustomMasterUrl = "/_catalogs/masterpage/nightandday.master"

$web.MasterUrl = "/_catalogs/masterpage/nightandday.master"

$web.Update() 
0

You do not require any powershell to apply the site collection master page on all subsites.

  1. Go to Root site collection -- > Site settings--> Master Page (under Look and Feel).
  2. Select your masterpage. Check "Reset all subsites to inherit this site master page setting" . Click Ok.

Now all your sub sites will inherit the masterpage of the root site.

  • Hi Unnie, thanks for the reply. But no idea where those settings are... Can you elaborate? Which SharePoint version are you talking about? – naijacoder Jul 1 '15 at 0:12
  • 1
    Foundation do not have publishing feature. This "inherit" thing should belong to publishing feature. – Mark L Mar 4 '16 at 3:49
0
    $site = Get-SPSite http://iddddp:100/
foreach ($web in $site.AllWebs)
{
    $web.MasterUrl = $site.RootWeb.ServerRelativeUrl +  "_catalogs/masterpage/seattle.master";
    $web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "_catalogs/masterpage/HMC_Master_IN.master";
    $web.Update();
    Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.