SharePoint Automation Gary Lapointe – Founding Partner, Aptillon, Inc.

20Aug/1111

Resetting SharePoint 2010 Themes – Part 2, the Reset-SPTheme cmdlet

Yesterday I threw up a quick post showing how to reset a SharePoint 2010 theme using a reasonably simple Windows PowerShell script. In that post I promised that I’d convert the script to a cmdlet and make it part of my downloadable extensions. Well, as promised I’ve updated my extensions so that they now include a Reset-SPTheme cmdlet. I added on minor enhancement over the previously shown script in that I allow you to pass in either an SPSite or an SPWeb object and by default it will not force all child webs to inherit from the relevant SPWeb object. This way, if you have a child Site with it’s own theme it won’t wipe out that theme. If you have multiple Sites with a custom theme setting within a Site Collection then you’ll want to provide the -Site parameter and pass in an SPSite reference – this will result in all Sites with custom themes within the Site Collection to be reset. If you only wish to reset a single Site then use the -Web parameter and pass in a SPWeb reference.

Here’s the full help for the Reset-SPTheme cmdlet:

NAME
    Reset-SPTheme

SYNOPSIS
    Resets a theme by applying all user specified theme configuration settings to the original source files. This is particularly helpful when the original source files have changed to a Feature upgrade.

SYNTAX
    Reset-SPTheme [-Web] <SPWebPipeBind> [-SetSubWebsToInherit <SwitchParameter>] [-AssignmentCollection <SPAssignmentCollection>] [<CommonParameters>]

    Reset-SPTheme [-Site] <SPSitePipeBind> [-SetSubWebsToInherit <SwitchParameter>] [-AssignmentCollection <SPAssignmentCollection>] [<CommonParameters>]

DESCRIPTION
    Resets a theme by applying all user specified theme configuration settings to the original source files. This is particularly helpful when the original source files have changed to a Feature upgrade.

    Copyright 2011 Falchion Consulting, LLC
    > For more information on this cmdlet and others:
    >
http://blog.falchionconsulting.com/
    > Use of this cmdlet is at your own risk.
    > Gary Lapointe assumes no liability.

PARAMETERS
    -Web <SPWebPipeBind>
        Specifies the URL or GUID of the Web containing the theme to reset.

        The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid name of Microsoft SharePoint Foundation 2010 Web site (for example, MySPSite1); or an instance of a valid SPWeb object.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       true (ByValue, ByPropertyName)
        Accept wildcard characters?  false

    -Site <SPSitePipeBind>
        The site containing the theme to reset.

        The type must be a valid GUID, in the form 12345678-90ab-cdef-1234-567890bcdefgh; a valid URL, in the form http://server_name; or an instance of a valid SPSite object.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       true (ByValue, ByPropertyName)
        Accept wildcard characters?  false

    -SetSubWebsToInherit [<SwitchParameter>]
        If specified, all child webs will be reset to inherit the theme of the specified web or root web.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -AssignmentCollection [<SPAssignmentCollection>]
        Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.

        When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        "get-help about_commonparameters".

INPUTS

OUTPUTS

NOTES

        For more information, type "Get-Help Reset-SPTheme -detailed". For technical information, type "Get-Help Reset-SPTheme -full".

    ------------------EXAMPLE 1-----------------------

    PS C:\> Get-SPSite http://server_name | Reset-SPTheme -SetSubWebsToInherit

    This example resets the theme for the site collection http://server_name and resets all child webs to inherit from the root web.

    ------------------EXAMPLE 2-----------------------

    PS C:\> Get-SPWeb http://server_name/sub-web | Reset-SPTheme

    This example resets the theme for the web http://server_name/sub-web.

RELATED LINKS
    Get-SPWeb
    Get-SPSite

 

In the following example I’m resetting the theme(s) for an entire Site Collection. If one any child Sites within the Site Collection have a custom theme then they’ll be updated, not just the root (inheritance will not be changed):

PS C:\> Reset-SPTheme -Site http://example.com

In this next example I’m resetting all child Sites to inherit whatever theme has been specified for the root Site and I’m updating the root Site’s theme with changes to the source files:

PS C:\> Reset-SPTheme -Site http://example.com -SetSubWebsToInherit

For this last example I’m resetting the theme of a specific sub-Site:

PS C:\> Reset-SPTheme -Web http://example.com

As you can see, this is pretty easy to use and, if you’re deploying your branding via Features and you have theme support then a cmdlet like this can be quite critical when you need to push out updates to that brand.

Comments (11) Trackbacks (0)
  1. Hi Gary,

    btw, we make the activity for SharePoint workflow to execute PowerShell scripts from workflows:

    http://www.harepoint.com/Products/HarePointWorkflowExtensions/ListActivities.aspx#development

    WBR, Alexander

  2. On occasion I can see needing to run a script like this to reset the themes of a few thousand site collections on one of our farms. How long would you guess such a feat might take? Hours… days… I’m crazy for thinking of doing it?

    • On the environment I was working on that needed this it took 5-10 seconds per site collection so I’d plan on somewhere around 2-3 hours of run time per thousand. The task is pretty IO intensive so I’d definitely do it during off hours :)

  3. Gary, firstly, awesome cmdlet. I’d thought about writing the same thing myself but thought I better check that you hadn’t already created it…. lo and behold you’ve done the work for me.

    I am however getting an error when I attempt to execute the cmdlet using:

    Reset-SPTheme -Site http://sandpit -verbose

    Get get the following response:

    VERBOSE: Leaving BeginProcessing Method of Reset-SPTheme.
    Reset-SPTheme : The Web application at http://_catalogs/theme/Themed/329652EFB596429C991DB8AB8781CF55/theme.thmx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
    At line:1 char:14
    + Reset-SPTheme <<<< -Site http://sandpit -verbose
    + CategoryInfo : InvalidData: (Lapointe.ShareP…mdletResetTheme:SPCmdletResetTheme) [Reset-SPTheme], FileNotFoundException
    + FullyQualifiedErrorId : Lapointe.SharePoint2010.Automation.Cmdlets.Themes.SPCmdletResetTheme

    VERBOSE: Leaving ProcessRecord Method of Reset-SPTheme.
    VERBOSE: Leaving EndProcessing Method of Reset-SPTheme.

    Any ideas?

  4. Ive got the same Problem like Paul!

  5. How would you go about resetting this for one user within the domain? I have a user who has set a theme and he now cant access OWA properly.

  6. Gary – Awesome… However – just discovered that I have a small problem … After migrating a 2007 site (which had a custom theme) to 2010 – and then switching to the new UI – I discovered this won’t run…

    After a bit of digging with Designer – I discovered that _catalogs\theme is simply missing … so uploading fails…

    I’ve tried manually creating a folder there with Designer an populating with Themes / Forms(aspx) from another working 2010 server – but that doesn’t work … Appears that _catalogs\theme has properties for document library, etc.. that can’t be set on a “folder”…

    Any idea / advice on how to create / populate the Gallery AFTER the fact when it’s missing would be greatly appreciated….

    I’m about to submit to yet another migration to solve this – elsewhere I saw that setting to the default theme PRIOR to migration is the key…


Leave a comment

CAPTCHA Image

*

No trackbacks yet.