PowerShell for SCSM: Delete Work Items and Activities
Quite often you need to delete an incident, activity or other SCSM work item. Using PowerShell is an easy way to do this.

This blog post was based of the Travis Wright's blog: Using SMLets Beta 3 Post #9–Deleting Objects
Work Item Class
The first thing you will need, is the Class of each work item:
Remove ALL objects
SMLets Remove-SCSMObject is very powerful and these commands should only be used in a lab or test environment. They will delete ALL items in the class. These do not check the status of the work item (In Progress, Pending, Completed, Closed ,etc).
When deleting an work item with activities (CR, SR, RR) the child activities are also deleted (regardless of status).
Only use in a lab or test environment. Be very careful.
Delete a Specific Work Item
This is more useful as it targets one object to delete. It uses the filter option to find the specific item and then removes it.
Delete all activities on a Work Item
In this example we will delete all the activities on a specific Service Request. The command is recursive and will delete any any of the lower nested activities.
The main issue is that you have to know what types of activities you are deleting. The System.WorkitemActivity will cover the default out of the box Manual, Review, Dependent, Parallel, Sequential activities. I have also added in a Runbook Activity. But if you have third party or custom activities you will need to add them to the list.
Use SCSM Entity Explorer to check what relationships and classes are being used on the work item. From this you can add extra types to activities. Or you can use this command to see relat4d objects on the work item, in this case Service request:
And an example if you have used a Xapity PowerShell, Create or Notification Activity
A list of our posts related to PowerShell:
PowerShell for SCSM: Download Attachments
PowerShell for SCSM: Copy Attachments from Disk to a Work Item
PowerShell for SCSM: Copy parent Attachments to Child Activity
PowerShell for SCSM: Copy Parent Description to Child Activities
PowerShell for SCSM: Activity Work Item tags
PowerShell for SCSM: Copy Approvers to Child Review Activities
PowerShell for SCSM: Pull Data via Relationship to Work Item
PowerShell for SCSM: Push Data via Relationship to Work Item
PowerShell for SCSM: How to get the parent Work Item of an SCSM Activity
Xapity Create Activity and Xapity PowerShell Activity
PowerShell for SCSM: Software Request Example
PowerShell for SCSM: Updating the Action Log
PowerShell for SCSM - Delete Action Log Comments
Xapity PowerShell Activity - Features
PowerShell for SCSM: Use PowerShell Scripts in Workflows
PowerShell for SCSM: Remove and Add Reviewers to In Progress Change Requests
PowerShell for SCSM: Submit Documents for Approval
PowerShell Scripting: Working with History Tab Information
PowerShell for SCSM: Bulk Update Classifications
PowerShell For SCSM: Portal Request on Behalf other user
PowerShell for SCSM: Activity Status - Skip, Complete, Rerun
PowerShell for SCSM: Delete Work Items and Activities