none
PowerShell Online has no Microsoft.SharePoint.Client.Utilities.ThmxTheme RRS feed

  • Question

  • Hi All

    I need to create a PowerShell script for an Online SharePoint sites that resets the theme to the default theme. I can get the script working on premise ok using RemoveThemeFromWeb but there is no RemoveThemeFromWeb for SharePoint online

    1) On premise SP Site working OK:
           $spTheme = [Microsoft.SharePoint.Utilities.ThmxTheme]::RemoveThemeFromWeb($spWeb,$true) 

    2) SharePoint Online Site not working:
            $spTheme = [Microsoft.SharePoint.Client.Utilities.ThmxTheme]::RemoveThemeFromWeb($spWeb,$true) 
            Unable to find type [Microsoft.SharePoint.Client.Utilities.ThmxTheme].

    ************* CODE *************
    $loc = "C:\Users\Test\Desktop\dll\"
    $user ="TestUser@Outlook.com"
    $site = "https://TestSite.sharepoint.com/sites/Dev1/"

    Set-Location $loc

    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
    Write-Host "Add Password"
    $SecPass = Read-Host -AsSecureString
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($site);
    $cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$SecPass)
    $context.Credentials = $cred
    $spSite = $context.Site
    $spWeb = $spSite.RootWeb
    $context.Load($spWeb);
    $context.ExecuteQuery();
    Write-Host "Reset '$($spWeb.Title)' to the Default Theme " -ForegroundColor Green 
    $spTheme = [Microsoft.SharePoint.Client.Utilities.ThmxTheme]::RemoveThemeFromWeb($spWeb,$true) 
    # bool value states if you wish to also remove the theme’s styles.
    $spWeb.Update()   
    $context.ExecuteQuery();

    **********************************
    I hope you can help
    Colin




    • Edited by ceBlueSky Monday, January 16, 2017 3:22 AM
    Monday, January 16, 2017 3:19 AM

Answers

  • I got it working by using https://MySite.sharepoint.com/sites/Dev1/_catalogs/design/AllItems.aspx and $web.ApplyTheme:

    $loc = "C:\Users\User1\Desktop\dll\" # Location of DLL''s
    $siteUrl = "https://MySite.sharepoint.com/sites/Dev1"
    $loginname = "MyEmail@Outlook.com"
     
    Set-Location $loc
     
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")

    Write-Host "Please enter password for $($siteUrl):"
    $pwd = Read-Host -AsSecureString
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $pwd)
     
    $web = $ctx.Web
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    #$web.ApplyTheme( "/sites/Dev1/_catalogs/theme/15/palette007.spcolor","/sites/Dev1/_catalogs/theme/15/fontscheme002.spfont","/_layouts/15/images/image_bg007.jpg",$true)
    $web.ApplyTheme("/sites/Dev1/_catalogs/theme/15/palette011.spcolor","/sites/Dev1/_catalogs/theme/15/fontscheme002.spfont","/_layouts/15/images/image_bg011.jpg",$true)
    $web.update()
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    Write-Host "Title" $web.Title " has bee updated"




    • Marked as answer by ceBlueSky Friday, January 20, 2017 1:07 AM
    • Edited by ceBlueSky Friday, January 20, 2017 1:11 AM
    • Unmarked as answer by ceBlueSky Friday, January 20, 2017 1:13 AM
    • Marked as answer by ceBlueSky Friday, January 20, 2017 1:13 AM
    Friday, January 20, 2017 1:06 AM

All replies

  • Hi ceBlueSky,

    Unfortunately, currently, the latest SharePoint Online CSOM not provide such method to reset the theme in SharePoint Online.

    I suggest you can submit a user voice about this requirement to Microsoft Office 365 platform, so that it could be improve in the future.

    Office 365 user voice:

    https://officespdev.uservoice.com/

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by ceBlueSky Friday, January 20, 2017 12:48 AM
    • Unmarked as answer by ceBlueSky Friday, January 20, 2017 1:05 AM
    Tuesday, January 17, 2017 8:19 AM
  • I got it working by using https://MySite.sharepoint.com/sites/Dev1/_catalogs/design/AllItems.aspx and $web.ApplyTheme:

    $loc = "C:\Users\User1\Desktop\dll\" # Location of DLL''s
    $siteUrl = "https://MySite.sharepoint.com/sites/Dev1"
    $loginname = "MyEmail@Outlook.com"
     
    Set-Location $loc
     
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
    Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")

    Write-Host "Please enter password for $($siteUrl):"
    $pwd = Read-Host -AsSecureString
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($loginname, $pwd)
     
    $web = $ctx.Web
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    #$web.ApplyTheme( "/sites/Dev1/_catalogs/theme/15/palette007.spcolor","/sites/Dev1/_catalogs/theme/15/fontscheme002.spfont","/_layouts/15/images/image_bg007.jpg",$true)
    $web.ApplyTheme("/sites/Dev1/_catalogs/theme/15/palette011.spcolor","/sites/Dev1/_catalogs/theme/15/fontscheme002.spfont","/_layouts/15/images/image_bg011.jpg",$true)
    $web.update()
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    Write-Host "Title" $web.Title " has bee updated"




    • Marked as answer by ceBlueSky Friday, January 20, 2017 1:07 AM
    • Edited by ceBlueSky Friday, January 20, 2017 1:11 AM
    • Unmarked as answer by ceBlueSky Friday, January 20, 2017 1:13 AM
    • Marked as answer by ceBlueSky Friday, January 20, 2017 1:13 AM
    Friday, January 20, 2017 1:06 AM