Saturday, 15 February 2014

Applying/Change the CustomMasterUrl and MasterUrl in master page setting in SharePoint using PowerShell

Provide the URL in $webAppUrl and Below is the code details:-

param($webAppUrl)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration")
 
$site=New-Object Microsoft.SharePoint.SPSite($webAppUrl)
$web = $site.openweb();
$web.AllowUnsafeUpdates=$true;
$MasterPageURL="/_catalogs/masterpage/XYZ_publishing.master"
$web.CustomMasterUrl=$MasterPageURL
$web.MasterUrl=$MasterPageURL
$web.Update()
$web.AllowUnsafeUpdates=$false;
$outputText = "XYZ publishing master page is applying in "+ $web.Name +" site."
write-output $outputText
                                
$web.Dispose()
$site.Dispose()

No comments:

Post a Comment