Modify an closed incident via powershell

Hello Experts,

I have a need to modify specific incidents via PowerShell; specifically to add/remove a CI. Since the status is set to closed, I cannot reactivate the incident and change the fields via console due to legal requirements (I also cannot change it while it's closed because I have a form assembly preventing changes to closed incidents).

That being said I must modify them through PowerShell so I began writing a script to try it out. I have the variables I may or may not need for getting the correct relationship and CI class, I'm stuck at what the property should be in the property hash-table and would appreciate any guidance.

Here is what I have so far:

$IncidentClass = Get-SCSMClass -Name System.WorkItem.Incident$
$CIclass = Get-SCSMclass -Name COMPANY.CI.Class$
$RelWIaboutCI = Get-SCSMRelationshipClass -Name System.WorkItemAboutConfigItem$

$CIToAdd = "Example CI"
$Incident = Get-SCSMObject -Class $IncidentClass -Filter "DisplayName -like '%IR41010%'"
$PropertyHashTable = @{"Affected Items" = $CIToAdd}

$AffectedCI = Set-SCSMObject -SMObject $Incident -PropertyHashtable

September 14th, 2015 11:12am

You need to get the CI object and add a new relationship object where source is the Incident and Target is the CI object:

$IncidentClass = Get-SCSMClass -Name System.WorkItem.Incident$
$CIclass = Get-SCSMclass -Name COMPANY.CI.Class$ 
$RelWIaboutCI = Get-SCSMRelationshipClass -Name System.WorkItemAboutConfigItem$

$CIToAdd = Get-SCSMObject -Class $CIclass -Filter "DisplayName -like 'Example CI'"

$Incident = Get-SCSMObject -Class $IncidentClass -Filter "Id -eq IR41010"

New-SCSMRelationshipObject -Relationship $RelWIaboutCI -Source $Incident -Target $CIToAdd -Bulk

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 2:19pm

New-SCSMRelationshipObject is what I needed :) Greatly appreciated, Thanks!
September 14th, 2015 2:49pm

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

Other recent topics Other recent topics