Created
August 26, 2016 10:59
-
-
Save reshmee011/1ca45106f979f8b2b03303517494f551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Apply theme and create composed look | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$SiteUrl, | |
[Parameter(Mandatory=$false)] | |
[string]$themeName ="EDRMS1", | |
[Parameter(Mandatory=$false)] | |
[string]$colorFilePath = "Palette031.spcolor" , | |
[Parameter(Mandatory=$false)] | |
[string]$backGroundPath = "image_bg009.jpg", | |
[Parameter(Mandatory=$false)] | |
[string]$FontFilePath = "fontscheme001.spfont", | |
[Parameter(Mandatory=$false)] | |
[int]$DisplayOrder =11, | |
[Parameter(Mandatory=$false)] | |
[string]$masterPageName | |
) | |
Set-Location $PSScriptRoot | |
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" | |
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" | |
##$username = Read-Host -Prompt "Enter userName"; | |
$username = "ppf-it\auckloor"; | |
$password = Read-Host -Prompt "Enter password" -AsSecureString ; | |
$spContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl); | |
$spContext.Credentials = New-Object System.Net.NetworkCredential($username, $password); | |
function IfThemeExists($ctx,$list,$themeName) | |
{ | |
$caml="<View><Query><Where><Eq><FieldRef Name='Name' /><Value Type='Text'>$themeName</Value></Eq></Where></Query></View>"; | |
$cquery = New-Object Microsoft.SharePoint.Client.CamlQuery | |
$cquery.ViewXml=$caml | |
$listItems = $list.GetItems($cquery) | |
$ctx.Load($listItems) | |
$ctx.ExecuteQuery() | |
if($listItems.Count>0) | |
{ | |
return $true; | |
} | |
else | |
{ | |
return $false; | |
} | |
} | |
$web = $spContext.Web; | |
$spContext.Load($web); | |
$spContext.ExecuteQuery(); | |
## get the composite look gallery to create composed look | |
$themesOverviewList = $web.GetCatalog(124); | |
$spContext.Load($themesOverviewList); | |
$spContext.ExecuteQuery(); | |
## Do not add duplicate, if the theme is already there | |
##TODO | |
if ((IfThemeExists -ctx $spcontext -list $themesOverviewList -themeName $themeName) -eq $false) | |
{ | |
## Create new theme entry. | |
$itemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation | |
$item = $themesOverviewList.AddItem($itemInfo) | |
$item["Name"] = $themeName; | |
$item["Title"] = $themeName; | |
$themeUrl = $web.ServerRelativeUrl + "/_catalogs/theme/15/" + $colorFilePath; | |
$FontSchemeUrl = $web.ServerRelativeUrl + "/_catalogs/theme/15/" + $FontFilePath; | |
$BckImageUrl = $web.ServerRelativeUrl + "/_catalogs/theme/15/" + $backGroundPath; | |
## Use seattle master if not provided | |
if($masterPageName) | |
{ | |
$MasterPageUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/" + $masterPageName; | |
} | |
else | |
{ | |
$MasterPageUrl = $web.ServerRelativeUrl + "/_catalogs/masterpage/seattle.master"; | |
} | |
if ($colorFilePath) | |
{ | |
$item["ThemeUrl"] = $themeUrl; | |
} | |
if ($fontFilePath) | |
{ | |
$item["FontSchemeUrl"] = $FontSchemeUrl; | |
} | |
if ($backGroundPath) | |
{ | |
$item["ImageUrl"] = $BckImageUrl; | |
} | |
## Use seattle master if not provided | |
$item["MasterPageUrl"] = $MasterPageUrl ; | |
$item["DisplayOrder"] = $DisplayOrder; | |
$item.Update() | |
$spContext.ExecuteQuery(); | |
} | |
$web.ApplyTheme($themeUrl, $FontSchemeUrl,$BckImageUrl,$true) | |
$web.Update() | |
$spContext.ExecuteQuery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment