Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I am trying to update the theme on the SharePoint site to Green. Company colors pretty close. Anyway, the code runs flawlessly. But borks the site badly.

I can get it back to what I need but I need this code to work. I have around 500 SharePoint sites to update and well this is just failing.

URL changed to protect the innocent (ME)

What it looks like after the elephant borkings. Rod: Borked SharePoint site? Anyone?[^]

<pre lang="text">
Code Example.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.SharePointOnlineCredentials")

$tempC = new-object System.Net.WebClient
$tempC.UseDefaultCredentials=$true
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext("http://bergren.net/")
$Ctx.Credentials=$tempC.Credentials

#Get the Web
$Web = $Ctx.web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()

#Frame Master page URL
$MasterPageURL = "$($web.ServerRelativeUrl)/_catalogs/masterpage/seattle.master"

#Set Default Master page & Custom Master page
$web.CustomMasterUrl = $MasterPageURL
$Web.MasterUrl = $MasterPageURL
$web.Update()
$Ctx.ExecuteQuery()

$fontSchemeUrl = "$($web.ServerRelativeUrl)/_catalogs/theme/15/fontscheme003.spfont"
$themeurl = "$($web.ServerRelativeUrl)/_catalogs/theme/15/Palette013.spcolor"
$imageUrl = "$($web.ServerRelativeUrl)/_layouts/15/images/siteIcon.png?rev=23"

$web.ApplyTheme($themeurl, $fontSchemeUrl, $imageUrl, $false)
$web.Update()
$Ctx.ExecuteQuery()

What I have tried:

I have messed with the code alot. I have also tried Server side code on the SharePoint servers that pretty much do the same thing. Everything ends up looking like this.
Posted
Updated 10-Jul-18 5:50am
Comments
rnbergren 10-Jul-18 9:41am    
PS, I have googled extensively all the solutions I come across say the above code should work.

1 solution

#last few lines changed to this.

$nn = Out-Null

"applying theme"
$web.ApplyTheme($themeurl, $nn, $nn, $true);
$web.Update()
$Ctx.ExecuteQuery()

#Works fine now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900