0

I have an office 365 SharePoint site. I have applied a custom master page using CSOM powershell on my root site and it is applied on the site but the Master page is not applying on site settings page. When I see in site settings -> master page, the value is set as my custom master page in both

  1. Site Master Page
  2. System master page

any idea?

1 Answer 1

0

Try this script

 ##============================================ Setup Input Paths ===========================================================

 cls

 $Host.UI.RawUI.WindowTitle = "-- Change the Master Page to the Custom Master Page --"

 $StartDate = Get-Date
 Write-Host -ForegroundColor White "------------------------------------"
 Write-Host -ForegroundColor White "| Change the Master Page to the Custom Master Page |"
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 Write-Host -ForegroundColor White "------------------------------------"

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".\ChangeMasterPage-$LogTime.rtf"

 #start-transcript $logfile

 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase

 $ErrorActionPreference = "Stop"

 function AddPowerShellSnapin()
 {
     try
     {
         Write-Host "Adding PowerShell Snap-in" -ForegroundColor Green
         # Try to get the PowerShell Snappin.  If not, then adding the PowerShell snappin on the Catch Block
         Get-PSSnapin "Microsoft.SharePoint.PowerShell"
     }
     catch
     {
         if($Error[0].Exception.Message.Contains("No Windows PowerShell snap-ins matching the pattern 'Microsoft.SharePoint.PowerShell' were found"))
         {
             Add-PSSnapin "Microsoft.SharePoint.PowerShell"
         }
     }
     Write-Host "Finished Adding PowerShell Snap-in" -ForegroundColor Green
 }

 function UpdateMasterPage([string]$webURL)
 {
     $web = Get-SPWeb $webURL
 #Change the masterpage
     $web.CustomMasterUrl = "/services/GVI/_catalogs/masterpage/MyMaster.master"

 #Change the System Master Page
     $web.MasterUrl = "/services/GVI/_catalogs/masterpage/ MyMaster-System.master"
     $web.Update()
 }

 try
 {
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration")

     $ConfigXmlPath = $scriptBase + "\ConfigXML\Configuration.xml"
     Write-Host "Read the Config Values" -ForegroundColor Green 
     [Xml]$Config = Get-Content $ConfigXmlPath 

     AddPowerShellSnapin

     UpdateMasterPage $Config.Configuration.PublishingSite.URL  

 }
 catch
 {
     Write-Host "Custom Exception Happened on Main : " + $Error[0].Exception.Message -ForegroundColor Red  
 }

And the Config XML Will be like,

 <Configuration EnvironmentName="Dev/QA/UAT/PROD">
   <PublishingSite URL="http://MySiteCollectionURL" />

 </Configuration>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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