Skip to main content

recursively remove versions on a schedule

Given a start path, recursively clear out old versions to a maximum number in order to maintain editor performance. Run on a scheduled task to ensure full automation of the task.

  • Create new Powershell Script in the Script Library consisting of the code below
Write-Log "Starting recurse run of /sitecore/content/pathtohome/ to remove versions, maxRecentVersions = 5"

Remove-ItemVersion -Path 'master:/sitecore/content/pathtohome/' -Recurse -Language "en-*" -MaxRecentVersions 5

Write-Log "Script complete"
  • Create a new Powershell Scripted Task Schedule with a suitable name under /sitecore/system/Tasks/Schedules
  • Set to async and configure to run at the desired frequency.
note
  • The Last Run field will indicate when the script was last run.
  • The SPE logs will contain the log entries from the script, indicating it's run instances
Troubleshooting
  • Should you find the script isn't running, right-click the schedule and Run Task Schedule to kick it off.