counter hit make
SCSM 2012: Auto Close resolved incidents after x days - Valérie's System Center Blog

Valérie's System Center Blog

A System Center Blog

SCSM 2012: Auto Close resolved incidents after x days

Service Manager 2012 now has a lot of built in cmdlets.
I used the built-in CMDlets to create a workflow which will disable all resolved incidents after a specified time.

There are several posts explaining how you can do this using the SMLets over here. Both workflows will do the same.

Open the Service Manager Authoring Tool and create a new Management Pack.
Give the management pack a name like AutoCloseResolvedIncidents

Right Click on workflow and select “New Workflow”.
Enter a name for this workflow.
Select “At specified time”, and let the workflow run once a day or even once a week according to your own preferences.

Drag the powershell icon to the workflow, click script content in the properties and paste the script below. This script will close all resolved incidents after 10 days. You can change the addhours parameter to another value if you like. Note this must be a negative value.

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

$Resolved = IncidentStatusEnum.Resolved;
$Closed = IncidentStatusEnum.Closed;

$DaysOld = (get-date).addhours(-240);
$IncidentClass = Get-SCClass –Name System.workitem.incident;

$IncidentsToClose = Get-SCClassInstance -Class $IncidentClass -Filter "Status -eq IncidentStatusEnum.Resolved" | where{$_.ResolvedDate -lt $daysold};

$IncidentsToClose | Foreach-Object{$_.Status = "IncidentStatusEnum.Closed"; Update-SCClassInstance -Instance $_};

Save the management pack. (If you receive an error when saving the management pack make sure all quotes “” and – are correctly pasted in the workflow).
Open an explorer and browse to the location where you saved the management pack. There should be a file <workflowname>.dll , copy this file and paste it in the Service Manager installation directory (Default: C:\Program Files\Service Manager 2012\)

Import the management pack using the service manager console.
You can track the workflow status in the Administration tab > Workflows > Status.