Need help using SMLets to determine whether a reviewer was ADDED
I want to know whether a reviewer was added to a RA using PowerShell.
Here's a snippet of my script:
$ScsmObjectGuid = "<RA GUID>"<br>$WorkItemObj = Get-SCSMObject -Id $ScsmObjectGuid<br>$WorkItemHistory = Get-SCSMObjectHistory -Object $WorkItemObj
What is returned is always "Modify", yet SCSM shows that the change type was an "Add" or "Remove".
How do I find the correct change type?
Best Answers
-
Geoff_Ross Cireson Consultant O.G.Hi Leigh,
I've done some testing and you are right, it seems the Get-SCSMObjectHistory cmdlet will always report the changes as Modify. I guess you would then have to check for a relationship between the two objects to know if it was Added or Removed. Quite an interesting issue,6 -
Nicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭Hi Leigh,
Review Activities can be a bit tricky, as there is not a single/direct link between the RA and Reviewers behind-the-scenes (although the SCSM console might lead you to believe otherwise).
What you are retrieving as a "Modify" change can instead by thought of as a container (relationship) in which the Reviewers sit. So, instead of a direct RA -> Reviewer relationship, it is closer to RA -> Reviewer Container -> Reviewers. As far the the History is concerned, whenever adding or removing Reviewers, the container is simply modified, not added or removed.
To get the actual users who are reviewers for this RA, the following code should retrieve those relationship objects:
Get-SCSMRelationshipObject -BySource $WorkItemObj | ?{$_.RelationshipId -eq "90da7d7c-948b-e16e-f39a-f6e3d1ffc921"}
Hope this helps!
Thanks,
Nick6
Answers
I've done some testing and you are right, it seems the Get-SCSMObjectHistory cmdlet will always report the changes as Modify. I guess you would then have to check for a relationship between the two objects to know if it was Added or Removed. Quite an interesting issue,
Review Activities can be a bit tricky, as there is not a single/direct link between the RA and Reviewers behind-the-scenes (although the SCSM console might lead you to believe otherwise).
What you are retrieving as a "Modify" change can instead by thought of as a container (relationship) in which the Reviewers sit. So, instead of a direct RA -> Reviewer relationship, it is closer to RA -> Reviewer Container -> Reviewers. As far the the History is concerned, whenever adding or removing Reviewers, the container is simply modified, not added or removed.
To get the actual users who are reviewers for this RA, the following code should retrieve those relationship objects:
Get-SCSMRelationshipObject -BySource $WorkItemObj | ?{$_.RelationshipId -eq "90da7d7c-948b-e16e-f39a-f6e3d1ffc921"}
Hope this helps!
Thanks,
Nick
System.ReviewActivityHasReviewer
and
System.ReviewerIsUser
We are grabbing the System.ReviewerIsUser relationship objects in this case.