When you deploy Service Manager into an environment, there will be times when you will need to test and make sure all is working before you deliver the end product to the appropriate person or business. By doing that you might end up with lots of test Work Items (Incidents, Service Requests, Activities, Problems, Change Requests) that you can’t delete from the Console directly. To overcome this, you can use PowerShell or Service Manager Shell to delete the Work Items directly from the Database.

Bear in mind that once deleted, you can’t retrieve them anymore, so make sure you really want them deleted and that you are deleting the right one.

 

Table of Contents

Getting started

If you choose to use PowerShell, We’ll start by finding your Service Manager install directory, where is has its PowerShell module saved as you might need to import it. The default location is ‘C:\Program Files\Microsoft System Center\Service Manager\Powershell\System.Center.Service.Manager.psd1’. If you choose to use Service Manager Shell, you can just start it from the Start Menu as Administrator.

If using PowerShell, You can import the SMlets, You don’t need this if using Service Manager Shell. Always Open PowerShell as Administrator to give your the right permissions to carry on these tasks.

				
					Import-Module 'C:\Program Files\Microsoft System Center\Service Manager\Powershell\System.Center.Service.Manager.psd1' -force
				
			

Incidents

Delete Incidents 1 by 1

				
					Import-Module SMLets

$IncidenteID = Read-Host "Enter Incident Number"

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Incident) | Where-Object {$_.ID -eq "$IncidenteID"} | Remove-SCSMClassInstance
				
			

Delete Incidents all at once

				
					Import-Module SMLets

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Incident) | Where-Object {$_.ID -ilike "IR*"} | Remove-SCSMClassInstance
				
			

Service Request

Delete Service Requests 1 by 1

				
					Import-Module SMLets

$RequestID = Read-Host "Enter Service Request Number"

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest) | Where-Object {$_.ID -eq “$RequestID”} | Remove-SCSMClassInstance
				
			

Delete Service Requests all at once

				
					Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem. ServiceRequest) | Where-Object {$_.ID -ilike "SR*"} | Remove-SCSMClassInstance
				
			

Change Request

Delete Changes Requests 1 by 1

				
					Import-Module SMLets

$ChangeRequestID = Read-Host "Enter Change Request Number"

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.ChangeRequest) | Where-Object {$_.ID -eq "$ChangeRequestID"} | Remove-SCSMClassInstance
				
			

Delete Change Request all at once

				
					Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.ChangeRequest) | Where-Object {$_.ID -ilike "CR*"} | Remove-SCSMClassInstance
				
			

Activities

Delete Activities 1 by 1

				
					Import-Module SMLet

$ActivityID = Read-Host "Enter Manual Activity Number"

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Activity) | Where-Object {$_.ID -eq "$ActivityID"} | Remove-SCSMClassInstance
				
			

Delete Activities all at once

				
					# Define which activity type in $ActivityID variable (Manual=MA, Review=RA...) then add the * after the ID in the prompt. EG: RA*

Import-Module SMLet

$ActivityID = Read-Host "Set Your Activity Type"

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Activity) | Where-Object {$_.ID -ilike "$ActivityID"} | Remove-SCSMClassInstanc
				
			

Problems

Delete Problems all at once

				
					Import-Module SMLets

Get-SCSMClassInstance -Class (Get-SCSMClass -Name System.WorkItem.Problem) | Where-Object {$_.ID -ilike "PR*"} | Remove-SCSMClassInstance