Domanda

So I have powershell code to upload a palette file to my themes gallery but I cannot seem to figure out how to create the composed look in the composed look gallery using the link to my uploaded theme in sharepoint 2016/2013 in powershell, any suggestions?

Here is my current code:

If(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0)){
Write-Progress -Activity "Loading Modules" -Status "Loading Microsoft.SharePoint.PowerShell"
   Add-PSSnapin Microsoft.SharePoint.PowerShell
   }

cls

$web = get-spweb http://test.site.com

<# Create composed look start #>
foreach($site in $web.Site.Allwebs)
{

    <# Upload Palette to Themes Gallery in rootsite Start #>
    try
    {
    $rootWeb = get-spweb $site.Site.RootWeb.Url

    $DocLibName = “_catalogs/theme” #Themes Library Name
    $FilePath = “C:\temp\colorPalette.spcolor” #Local path to palette file

    $List = $rootWeb.GetFolder($DocLibName) 
    $Files = $List.Files

    $FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)

    # Load the file into a variable 
    $File= Get-ChildItem $FilePath

    # Upload it to SharePoint 
    $Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false)
    }
    catch
    {
    #
    }
    <# Upload Palette to Themes Gallery in rootsite End #>

    <# Verify Site not root site Start #>
    if($site.Url -ne $site.Site.RootWeb.Url)
    {
    $paletteUrl = $site.Site.RootWeb.Url + "/_catalogs/theme"
    $paletteUrl

    $compositeLookGallery = $site.GetCatalog(124)
    #$site.Load($compositeLookGallery)
    $spContext = New-Object Microsoft.SharePoint.Client.ClientContext($site.Url);
    }
    <# Verify Site not root site End #>
}
<# Create composed look End #>
È stato utile?

Soluzione

this should help

 #region ######   Upload theme files   ###### 
try{
    $ColorFilePartUrl = "/_catalogs/theme/15/"
    $FontFilePartUrl = "/_catalogs/theme/15/"
    $MasterPagePartUrl = "/_catalogs/masterpage/"

    Write-Host "$SiteUrl + " :: " + $ThemeName + " :: " + $SpColorFileName + " :: " + $SpFontFileName + " :: " + $Masterpage"


    $TargetWeb = Get-SPWeb -Identity $UrlNewSite  
    Write-Host "processing: " $TargetWeb.Title
    $TargetWeb.allowunsafeupdates = $true
    $RelativeUrl = $TargetWeb.ServerRelativeUrl
    $SpList = $TargetWeb.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::DesignCatalog)

    $ThemeList = $TargetWeb.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::ThemeCatalog)
    $Folder = $ThemeList.RootFolder.SubFolders["15"]

    $ColorSchemeBytes = [System.IO.File]::ReadAllBytes($PathToColorSheme)
    $Folder.Files.Add($SpColorFileName,$ColorSchemeBytes,$true)

    try{
        $FontSchemeBytes = [System.IO.File]::ReadAllBytes($PathToColorSheme)
        $Folder.Files.Add($SpFontFileName,$fontSchemeBytes,$true)
    }
    catch{
        Write-Host "No valid spfont file found" -ForegroundColor Yellow
    }
    Write-Host "Upload of theme files...completed" -ForegroundColor Green
}
catch
{
    Write-Host "Caught an exception while uploading theme files:" -ForegroundColor Red
    Write-Host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
    Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
}$ErrorActionPreference = "Stop"
#endregion

#region ######   Create and apply theme to site   ######
try
{
    $ThemeUrlColor = $UrlNewSite+$ColorFilePartUrl+$SpColorFileName
    $ThemeUrlFont  = $UrlNewSite+$FontFilePartUrl+$SpFontFileName

    $SpColorFile=$TargetWeb.GetFile($ThemeUrlColor)

    try{
        $SpFontFile=$TargetWeb.GetFile($ThemeUrlFont)
    }
    catch{
        Write-Host "No valid spfont file found in $ThemeUrlFont" -ForegroundColor Yellow
    }

    $SPQuery1 =  New-Object Microsoft.SharePoint.SPQuery
    $SPQuery1.Query = "<Where><Eq><FieldRef Name='Name'/><Value Type='Text'>$ThemeName</Value></Eq></Where>"
    $SPQuery1.RowLimit = 1
    $SPQuery1.ViewFields = "<FieldRef Name='Name'/>"
    $SPQuery1.ViewFieldsOnly = $true

    $SpListItems1 = $SpList.GetItems($SPQuery1)

    if($SpListItems1.Count -eq 0)
    {        
        $NewThemeItem = $SpList.AddItem()

        $NewThemeItem["Name"] = $ThemeName
        $NewThemeItem["Title"] = $ThemeName
        $NewThemeItem["MasterPageUrl"] =  "$RelativeUrl$MasterPagePartUrl$Masterpage"
        $NewThemeItem["ThemeUrl"] = $ThemeUrlColor
        $newThemeItem["FontSchemeUrl"] = $ThemeUrlFont
        $NewThemeItem["DisplayOrder"] = 121
        $NewThemeItem.Update()
    }
    Write-Host "Create theme...completed" -ForegroundColor Green     
    $Theme=[Microsoft.SharePoint.Utilities.SPTheme]::Open($ThemeName, $SpColorFile)
    $Theme.ApplyTo($TargetWeb, $true)
    Write-Host "Apply theme...completed" -ForegroundColor Green 
}
catch
{
    Write-Host "Caught an exception while creating theme:" -ForegroundColor Red
    Write-Host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
    Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
}     
#endregion
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top