Monday, January 30, 2012

PowerShell: Reset all sites to default site definition

This PowerShell script will reset all sites within a site collection in SharePoint 2010 to t heir default site definition file. Very handy after doing a migration from MOSS 2007 to SPS2010, if you run into pages being broken due to formatting, etc.

// Will reset all sub-sites in a site collection
// to their default site definition.

$sitesToReset = @("http://contoso.sharepoint.com/")

$sitesToReset | ForEach-Object 
    {
 // Don't wait for user input.

        $DebugPreference = "SilentlyContinue"
        $web = Get-SPWeb $_

        $DebugPreference = "Continue"
        
        Write-Debug "Reghosting all pages in site ($($web.Url))..."

 // Reset definition.
        $web.RevertAllDocumentContentStreams()

 // Dispose site object.
        $web.Dispose()
    }

No comments:

Post a Comment