I found out my script to figure out the "Created By" value from a Service Request in SCSM was no longer functional.
it used to be :
here is how to achieve the same again:
and then you find all the relations for that request.
now step through all relations (all I get is a list of GUID's) but you can show the RelationsshipID, and if you feed that into the get-SCSMRelationship, you can see what relationship it is.
in my case I am only interested in the Created By User, so I step thru it till i find that one, and then I extract the display name of the user who created the service request.
you can do $Relations.TargetObject and it will show a list of all related target objects - it may help you to find what you're looking for :)
I had to figure this out by trial on error as I could not find anything about it.
actually,
it used to be :
$req = get-scsmclassinstance -class $cl -Filter "Id -eq $id"The command SCMSObjectHistory does no longer exist in SCSM
$inf = Get-SCSMObjectHistory -Object $req
$inf.History[0].UserName
here is how to achieve the same again:
$cl = get-SCSMClass -displayName "Service Request"so $req contains the details of the service request again
$req = get-scsmclassinstance -class $cl -Filter "Id -eq 'SR2577'"
$Relations = Get-SCSMRelationshipInstance -SourceInstance $req -TargetInstance $req
foreach ($Relation in $Relations)
{
if ((Get-SCSMRelationship ($Relation.RelationshipId)).DisplayName -eq "Created By User")
{
$ReqByName = ($relation.TargetObject).DisplayName
break #no need to continue the loop since there is only one Created By relation !
}
}
and then you find all the relations for that request.
now step through all relations (all I get is a list of GUID's) but you can show the RelationsshipID, and if you feed that into the get-SCSMRelationship, you can see what relationship it is.
in my case I am only interested in the Created By User, so I step thru it till i find that one, and then I extract the display name of the user who created the service request.
you can do $Relations.TargetObject and it will show a list of all related target objects - it may help you to find what you're looking for :)
I had to figure this out by trial on error as I could not find anything about it.
actually,