Skip to content

Instantly share code, notes, and snippets.

@patelcp
Forked from michaellwest/Clean up databases.ps1
Created December 29, 2017 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patelcp/d8e1703497c995a1e3884e4975813a04 to your computer and use it in GitHub Desktop.
Save patelcp/d8e1703497c995a1e3884e4975813a04 to your computer and use it in GitHub Desktop.
Run Sitecore rebuild and clean up tasks
<#
.SYNOPSIS
Runs a clean up for each database.
.NOTES
Michael West
#>
foreach($database in Get-Database) {
if(!$database.ReadOnly) {
Write-Log "Cleaning up the $($database) database."
$time = Measure-Command {
$database.CleanupDatabase()
}
Write-Log "Completed cleaning up the $($database) database in $($time.TotalSeconds) seconds."
}
}
<#
.SYNOPSIS
Rebuilds all the content search indexes.
.NOTES
Michael West
#>
foreach($index in [Sitecore.ContentSearch.ContentSearchManager]::Indexes) {
Write-Log "Rebuilding the $($index.Name) search index."
$time = Measure-Command {
$index.Rebuild()
}
Write-Log "Completed rebuilding the $($index.Name) search index in $($time.TotalSeconds) seconds."
}
<#
.SYNOPSIS
Rebuilds the search indexes.
.NOTES
Michael West
#>
foreach($index in [Sitecore.Search.SearchManager]::Indexes) {
Write-Log "Rebuilding the search index $($index.Name)"
$time = Measure-Command {
$index.Rebuild()
}
Write-Log "Completed rebuilding the search index $($index.Name) in $($time.TotalSeconds) seconds."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment