Reset to Site Definition via PowerShell in SharePoint

To Re-ghost customized SharePoint sites and pages, We use “Revert to Site definition” via

  • Site Settings >> under Site Actions section, click on Reset to site definition 
  • Choose a specific page or entire site. Click on Reset! .
Reset to Site Definition using PowerShell in SharePoint

Reset to site definition – what does it do?
Reset to Site Definition removes any customizations and reverts the file back to the version originally deployed via the Site Definition. Customized pages are stored in the Content Database (a copy with changes) and are called unghosted. When you reset, the customized copy gets deleted, and the version on the file system (the Site Definition version) is used.

Reset to Site Definition via PowerShell
When you have to reset a Site or List to its definition in bulk, PowerShell can be utilized.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$WebURL ="https://intranet.crescent.com/sites/operations/us"

$web =  Get-SPWeb $SiteURL
$web.RevertAllDocumentContentStreams();
$web.Update()

Let’s do it for All sites under the site collection:

$SiteURL ="https://intranet.crescent.com"

#Revert all webs to site definition
Get-SPSite $SiteURL | Get-SPWeb -Limit All | foreach-object {
 $_.RevertAllDocumentContentStreams()
 Write-Debug "Site Resetted: $($web.Url)"
 } 

All customizations will be reverted once the operation is completed.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “Reset to Site Definition via PowerShell in SharePoint

  • at the seconds script better it’s using parameter -limitall by GET-SPweb, because if we have many sites unde site collection , without -limitall the results will be not completly

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *