Quick Post: Delete SCSM Work Items created before specific date with PowerShell

Based on a post by Pete Zerger on systemcentercentral.com I created a PowerShell command which deletes all Work Items of a specific class in your CMDB when created before a specific date.

#Set date
$BeforeDate = Get-Date("31/1/2013").ToString("MM/dd/yyy HH:mm:ss")
#List incidents which were created before $BeforeDate
Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Incident) | Where {($_.CreatedDate -lt $BeforeDate)} | sort-object CreatedDate | ft -Property Id,Title,CreatedDate
#Remove instances
Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Incident) | Where {($_.CreatedDate -lt $BeforeDate)} | Remove-SCSMClassInstance

The commands could probably be optimized by using the -Filter parameter instead of the Where clause.

Comments

comments powered by Disqus