The PowerShell script delete all collections older than x days for a specific folder in Configuration Manager 2012.

It also create a small report in a text file that include the list of collections ID deleted.

The file will be integrate as an attachment in the email and will copy to any destination.

The file name contains the date so the script can be used on a daily basic and keep history.


Please make sure to modify the variables in the PowerShell script according to your infrastructure.

$SiteCode = Site code of your configuration manager infrastructure. (Default = CAS)
$SiteServer = The name of the site server of configuration manager.
$FolderName = The folder name you want to delete. You can use the wildcard % if it is more than one folder.
$Days = The number of days older you want to delete.
$FileDestination = The directory where you want to put the report file.
$EmailTo = The email address to who you want to send the report.
$EmailFrom = The email address from you want to send the report.
$SmtpServer = The SMTP server you want to use to send the report.

For more details, you can refer to this link