SCSM 2012 QuickTip: Retrieving the Assigned User Info for a Work Item via PowerShell (#scsm #scorch #sysctr)

I was doing some automation work with Service Manager 2012 and Orchestrator, and I needed to retrieve the name of the assigned user for incidents and service requests in a runbook. The challenge comes in that the Assigned User field is not simply a string, but is actually an object connected to the incident (or other work item). In order to get the assigned users display name, you have to traverse the relationship, retrieve the target of that relationship (the user object of the assigned to user in the CMDB) and then retrieve its DisplayName property.

Sample Script

I put together a quick PowerShell script using the Service Manager Command Shell that will perform these steps, ultimately returning the display name of the assigned user. I’ve added some comments to describe what’s happening at each step within the sample.

#——–Begin Sample Script——–#

#Retrieve the target workitem class (Incident in this case) and assign to a variable

$IRClass = get-scsmclass -name System.WorkItem.Incident

#Retrieve the relationship that connects the assigned user to the work item and assign to a variable

$AssignedToRel = get-scsmrelationshipclass -name System.WorkItemAssignedToUser$

#retrieve the incident for which you want to retrieve the assigned user and assign to a variable

$IR = get-scsmobject -class $IRClass -Filter “ID -eq IR6330”

#Retrieve the AssignedTo User for the incident and assign to a variable

$AssignedToUser = Get-SCSMRelatedObject -SMObject $IR -Relationship $AssignedToRel

#Retrieve AssignedTo User property you want (I was looking for DisplayName

$AssignedToUserDisplayName = $AssignedToUser.DisplayName

#Echo Assigned User DisplayName to the screen (for purposes of this example)

$AssignedToUserDisplayName

#——–End Sample Script——–#

 

NOTE: You can change the .Incident in line 1 to .ServiceRequest for a service request or .ChangeRequest for a chanage request.

2 thoughts on “SCSM 2012 QuickTip: Retrieving the Assigned User Info for a Work Item via PowerShell (#scsm #scorch #sysctr)

  1. Pingback: Accessing SCSM 2012 using PowerShell (without SMLets) | Ben Neise's Blog

  2. masood

    Hi Peter.

    In Service Manager there is no relationship available for the user who completed a Manual Activity . In our environment we assign an Activity to a group and someone in the group completes the manual  activity. I need to track the user who completed the activity.

    Could you please support me if you have any script for service request.

    Regards,

    Masood

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.