Service Manager – Which user?

One of the challenges when working with MS Service Manager 2012/2016 is that while there are related user types for things like the affected user (for whom the ticket is related) or the portal user (who put the ticket in), etc – most of the questions in which you choose an Active directory user – are simply related as “related to” and thus – if you as for multiple, you are not 100% sure which is the answer to the question asked.

I find myself frequently looking for a user specified in the questions in my powershell script.

Now one way to determine the actual user is to parse the XML from the answers block and get the name and the question. Match it up and you are good to go.

Anthony Watherson over at microsoft did a good writeup on that process – so I will just link that here:

https://blogs.technet.microsoft.com/automagically/2014/11/16/dealing-with-xml-inputs-from-service-manager/

However – I use something else – Not because it’s necessarily “better” but simply because it popped into my head when i was working on it – and I didn’t google for the XML solution until a much later date… i.e. when I was looking to talk about this content.

For me – I use Cireson’s “multiple mapping” feature to map the name of the user chosen, to a property in the SR:

and eventually handed off to SCORCH and the runbook :

So that gives us the NAME of the user chosen.. but how do we make sure it’s the right user? We might have two John Smiths of Sameer Kumars after all.

We pass that information along the chain to a SCORCH workflow:




The script grabs the user from the name – and passes it to the get object which then returns it to be used by whatever workflow you might need to use that information in.

here is the Powershell:

#
Find Related User
#
Import-Module SMLETS
$SCSMServer = "scsmserver.app.intranet"
$SCSMServer = "localhost"
Set base variables
$SR = "PASSED IN VARIABLE"
$name = "PASSED IN VARIABLE"
$SR = "SR172196"
Establish GUIDS:
$RelationShipType = "System.WorkItemRelatesToConfigItem"
Establish relationship classes
$RouteToRelationship = Get-SCSMRelationshipClass -Name $($RelationShipType +"$") -ComputerName $SCSMServer
$SystemWorkItemAssignedToUserClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$ -ComputerName $SCSMServer
Get Service Request
$ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$ -ComputerName $SCSMServer) -ComputerName $SCSMServer -Filter "ID -eq $SR"
Get user Object
$RoutedToUser = (Get-SCSMRelationshipObject -BySource $ServiceRequest -ComputerName $SCSMServer | ?{$_.RelationshipID -eq $RouteToRelationship.Id -and $_.IsDeleted -eq $False})
#
Foreach ($relateduserobj in $RoutedToUser)
{
$smuserobj = $relateduserobj.TargetObject
If ($smuserobj.displayname -eq $Name)
{
$Global:Userobject = $smuserobj
}
}
$SAM = $Userobject.Name
$ArrSAM = $SAM.Split(".")
#
$outSAM = $ArrSAM[1]
$outname = $Userobject.DisplayName
$outGUID = $Userobject.IdNow this may not be useful to you... b

We use this because we already have it. I was easy to put together when I was looking for a solution. Maybe it’s also useful to someone else… if not… I thank you for at least reading my ramblings 🙂