Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Set-SPOTheme{
- Param(
- [Parameter(Mandatory=$true)]$ctx,
- [Parameter(Mandatory=$true)]$spColorUrl,
- [Parameter(Mandatory=$true)]$shareGenerated,
- [string]$spFontUrl,
- [string]$backGroudUrl
- )
- try{
- write-host "Applying the theme to the site. " -NoNewline
- $spFontUrlAux = Out-Null #Needs to be set to Out-Null is empty
- If(![string]::IsNullOrEmpty($spFontUrl)){
- $spFontUrlAux = $spFontUrl
- } else {
- }
- $backGroudUrlAux = Out-Null #Needs to be set to Out-Null is empty
- If(![string]::IsNullOrEmpty($backGroudUrl)) {
- $backGroudUrlAux = $backGroudUrl
- }
- $web = $ctx.Web
- $web.ApplyTheme($spColorUrl, $spFontUrlAux, $backGroudUrlAux, $shareGenerated)
- $ctx.Load($web)
- $ctx.executeQuery()
- write-host " done." -ForegroundColor Green
- }
- catch{
- write-host "Error While applying the theme $($_.Exception.Message)" -foregroundcolor red
- }
- }
- 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"
- $siteUrl = Read-Host -Prompt "Provide the URL"
- $adminUsername = Read-Host -Prompt ("Provide user for {0}" -f $siteUrl)
- $secureAdminPassword = Read-Host -Prompt ("Provide password for {0}" -f $adminUsername) -AsSecureString
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUsername, $secureAdminPassword)
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $ctx.Credentials = $credentials
- #Sets only the Theme Colours
- Set-SPOTheme $ctx "/_catalogs/theme/15/palette010.spcolor"
- #Sets the Theme Colours and the fonts
- Set-SPOTheme $ctx "/_catalogs/theme/15/palette015.spcolor" $true "/_catalogs/theme/15/fontscheme001.spfont"
- #Sets the Theme Colours and the Image Background
- Set-SPOTheme $ctx "/_catalogs/theme/15/palette010.spcolor" $true $null "/_layouts/15/images/image_bg006.jpg"
- #Sets the Theme Colours, the fonts and the Image Background
- Set-SPOTheme $ctx "/_catalogs/theme/15/palette015.spcolor" $true "/_catalogs/theme/15/fontscheme003.spfont" "/_layouts/15/images/image_bg005.jpg"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement