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.
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)
#——–End Sample Script——–#
NOTE: You can change the .Incident in line 1 to .ServiceRequest for a service request or .ChangeRequest for a chanage request.