PowerShell/SCSM - Get the Work Item parent of an Activity

2016/02/23 | 1 minute read |

In the last couple of months, I have been busy on some projects involving System Center Service Manager (SCSM), System Center Orchestrator (SCORCH) and Cireson Portal/Asset Management and I had to script a couple of repetitive tasks using PowerShell.

The following solution allows you to retrieve the parent Work Item of an Activity.

This is useful when you are using a Runbook Activity in your workflow that will invoke a Runbook inside System Center Orchestrator.

Example: In the case where you have a Work Item, a Service Request for instance, with bunch of activities (Review Activity (RA), Manual Activity (MA), Runbook Activity (RBA), etc… ). You could have a Runbook Activity (RBA) calling a System Center Orchestrator runbook.

From a SCORCH perspective it would be useful to find which Work Item the runbook activity belongs to if you want to perform some actions on the Work Item itself and other Activities.

Example:

  • Edit the Work Item Title,
  • Add a reviewer,
  • Skip any Activities with a particular stage, etc…

Here is a PowerShell function that can just do this job for you: Get-SCSMWorkItemParent.

Get-SCSMWorkItemParent

# Load the function in your PS
. .\Get-SCSMWorkItemParent.ps1

# Or just copy the function in your powershell

Find the Work Item parent from an SMObject

# Get a Runbook Activity from SCSM
$RunbookActivity = Get-SCSMobject -Class (Get-SCSMClass -Name Microsoft.SystemCenter.Orchestrator.RunbookAutomationActivity$) -filter 'ID -eq RB12813'
# Get the RunbookActivity's WorkItem (parent)
Get-SCSMWorkItemParent -WorkItemObject $RunbookActivity

Find the Work Item parent from a GUID

# Retrieve the runbook Activity GUID
$RunbookActivity.get_id()
# Get the RunbookActivity's WorkItem (Parent) from the object GUID
Get-SCSMWorkItemParent -WorkItemGUID $RunbookActivity.get_id()

Download on github

Get-SCSMWorkItemParent on GitHub

Resources

Leave a Comment