Documentation Center

Purging old versions of content items

Whenever a user edits and saves an item, Content Manager creates a new version of the item so that you can track changes and roll back to previous versions of an item. If users update items often, multiple versions may cause the database to fill up. You can purge old versions of items in Windows PowerShell.

Before you begin

To purge old versions of content items, you must have system administration rights. You also need to have the DLL for purging loaded in PowerShell.

About this task

You can purge old versions of the following types of content items:

  • Components
  • Component Templates
  • Pages
  • Page Templates
  • Schemas
  • Template Building Blocks

It is not possible to delete versions of items that are currently checked out, nor can you delete the current (latest) version of an item.

Procedure

From the PowerShell command prompt, enter the command Remove-TcmItemsOldVersions, applying the following parameters:
ContainerItemIds

A String array of unique identifiers (Content Manager URIs and/or WebDAV URLs) of Publications, Folders and/or Structure Groups in which you want to purge all items. This is a positional argument at position 0: you do not need to supply the -ContainerItemIds switch and as a result, can pass this value from the previous command in a pipeline command.

VersionsToKeep

An optional unsigned integer (UInt32) indicating the (maximum) number of versions to keep for each item. For example, set this parameter to 2 to keep the last 2 versions of each item.

KeepVersionsModifiedAfter

An optional timestamp (DateTime) indicating the cutoff point after which no versions should be purged. For example, set this parameter to 17 January 2013 to keep all versions of items produced after that date.

KeepVersionsWithinDaysBeforeLastCheckIn

An optional unsigned integer (UInt32) indicating the (maximum) number of days prior to an item's last modification to keep versions. For example, set this parameter to 3 to keep all versions of items produced in the 3 days preceding its last modification.

Recursive

An optional parameter which, when included, also purges items in the subcontainers (and subsubcontainers, and so on) of the containers specified.

MaxResolvedItemsCount

An optional unsigned integer (UInt32) indicating the maximum number of items to purge. For example, set this parameter to 1000 to purge no more than 1000 items.

TimeOut

An optional integer (Int32) indicating the amount of time (in minutes) to wait before considering the purge operation to have timed out.

This setting only has effect if the amount of time you specify is shorter than the general timeout value for long queries (configurable in the longCommandTimeout attribute of the database element in Tridion.ContentManager.config), which itself defaults to 10 minutes if left unspecified.

If Timeout is left unspecified, the timeout defaults to the general timeout value set for long queries.

For example, the following command purges all item versions except the 5 most recent ones, in all Publications. If the procedure is not finished within half an hour, the command times out.

Remove-TcmItemsOldVersions -ContainerItemIds(Get-TcmRepository).Id -VersionsToKeep 5 -Recursive -TimeOut 30

SDL Tridion Sites purges the old versions of items that meet the criteria you specified. The return value is the number of item versions purged.