Can I schedule Remove-SCSMObject -Force?
Hi all, I would like to schedule every mounth Remove-SCSMObject for remove all Incidents that have priority 6,8,9. This is possible with the cmdlet bilow: $irClass = Get-SCSMClass -Name System.WorkItem.Incident$ Get-SCSMObject -Class $irClass | Where {$_.Priority -ne 8 -and $_.Priority -ne 9 -and $_.Priority -ne 6 -and $_.FirstAssignedDate -eq $null} | Remove-SCSMObject -Force I'm wondering what the impact of schedule deleting this behavior. Anybody out there using Remove-SCSMObject cmdlet in this way right now? Any suggestions on this? Thanks in advance for your help
June 6th, 2013 8:57am

I'm wondering what the reasoning behind deleting these is. It is generally not advised to delete incidents or other work items from Service Manager. If you just want a cleaner interface, I would suggest creating custom views to filter these out. If you still wish to perform this you will need to tweak your powershell command. The way you have it listed it will delete all incidents that are not priority 6,8, or 9. Also, you might consider putting in a filter to only delete closed incidents. Your current command would reopen incidents that are still active. You should use the -eq. An example of this would be: $irClass = Get-SCSMClass -Name System.WorkItem.Incident$ Get-SCSMObject -Class $irClass | Where {$_.Priority -eq 8 -and $_.Priority -eq 9 -and $_.Priority -eq 6 -and $_.FirstAssignedDate -eq $null -and $_.status -eq 'closed'} | Remove-SCSMObject -Force If you want to test you command you can remove the Remove-SCSMObject -Force from the command line and replace it with FT ID, Priority, Status -au. This would show you the ID, Priority, and Status of items would be removed, but it will not actually perform the delete action. $irClass = Get-SCSMClass -Name System.WorkItem.Incident$ Get-SCSMObject -Class $irClass | Where {$_.Priority -eq 8 -and $_.Priority -eq 9 -and $_.Priority -eq 6 -and $_.FirstAssignedDate -eq $null -and $_.status -eq 'closed'} | FT ID, Priority, Status -au
Free Windows Admin Tool Kit Click here and download it now
June 6th, 2013 10:13am

I'm wondering what the reasoning behind deleting these is. It is generally not advised to delete incidents or other work items from Service Manager. If you just want a cleaner interface, I would suggest creating custom views to filter these out. If you still wish to perform this you will need to tweak your powershell command. The way you have it listed it will delete all incidents that are not priority 6,8, or 9. Also, you might consider putting in a filter to only delete closed incidents. Your current command would reopen incidents that are still active. You should use the -eq. An example of this would be: $irClass = Get-SCSMClass -Name System.WorkItem.Incident$ Get-SCSMObject -Class $irClass | Where {$_.Priority -eq 8 -and $_.Priority -eq 9 -and $_.Priority -eq 6 -and $_.FirstAssignedDate -eq $null -and $_.status -eq 'closed'} | Remove-SCSMObject -Force If you want to test you command you can remove the Remove-SCSMObject -Force from the command line and replace it with FT ID, Priority, Status -au. This would show you the ID, Priority, and Status of items would be removed, but it will not actually perform the delete action. $irClass = Get-SCSMClass -Name System.WorkItem.Incident$ Get-SCSMObject -Class $irClass | Where {$_.Priority -eq 8 -and $_.Priority -eq 9 -and $_.Priority -eq 6 -and $_.FirstAssignedDate -eq $null -and $_.status -eq 'closed'} | FT ID, Priority, Status -au
June 6th, 2013 5:02pm

Thanks Matthew. I did same test in my lab, and the command is ok. Thanks for your help!
Free Windows Admin Tool Kit Click here and download it now
June 8th, 2013 4:09am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics