1

I'm using the built in SCSM cmdlets and the SMlets powershell module. I'm able to query Service Requests, but I can't seem to figure out how to get the Affected User of a given Service Request. I'm getting service requests in the following manner:

Import-Module SMlets -ErrorAction Stop

$SCSMclassSR = Get-SCSMClass -Name System.WorkItem.ServiceRequest
$SCSMobject = Get-SCSMObject -Class $SCSMclassSR

If you select any given ticket and run a Get-Member on it you can view the list of properties. None of which are mapping back to the Affected User. Thinking perhaps the ticket data is saved with the user object, I ran the following code:

$scsmuser = Get-SCSMObject -Class (get-scsmclass -name microsoft.ad.user) -filter "UserName -like <username>"

None of the properties there appear to map to any tickets (run a gm on it too). Granted, this could be ignorance on my part and the method to produce the tickets just isn't aptly named or described.

I've tried looking at the SMlets source code to glean some insight, but I'm not a C# developer so some of it goes over my head. I've also tried to get some understanding and help from the msdn page for EnterpriseManagementObject Class, but to no avail.

Hopefully there's a really simple solution to this and I'm just over thinking it. But, how do you get the Affected User for a SCSM ticket using powershell? Preferably a service request ticket.

MDMoore313
  • 5,531
  • 6
  • 34
  • 73
Colyn1337
  • 2,387
  • 2
  • 22
  • 38

1 Answers1

2

I kept digging and found a script online where someone wanted to find user email addresses for incidents. I figured they'd have to find the user first (which would give me the AffectedUser), and I was right. Here's the solution:

$SCSMclassSR = Get-SCSMClass -Name System.WorkItem.ServiceRequest
$SCSMobject = Get-SCSMObject -Class $SCSMclassSR

$affectedUserRelClass = Get-SCSMRelationshipClass System.WorkItemAffectedUser$

Foreach($SR in $SCSMobject){
        $affectedUser = Get-SCSMRelatedObject -SMObject $SR -Relationship $AffectedUserRelClass
        Add-Member -InputObject $SR -Name AffectedUser -Value $affectedUser.UserName -MemberType NoteProperty
}
Colyn1337
  • 2,387
  • 2
  • 22
  • 38