Using SMLets to remove all reviewers from a Review Activity
Does anyone know how this would be accomplished? I feel like I am close, I can obtain all of the RA reviewers with Get-SCSMRelatedObject -SMObject $RAToModify -Relationship $raHasReviewerRelClass
But, removing seems like a more complex task, undoubtedly due to multiple relationships being in play.
This is all stemming from a new SR I've created based on a template. All with SMLets, I create the SR, then apply the Projection (template) which contains the RA. In the Template, the RA is completely blank, including Reviewers. Somewhere along the line, a "phantom" reviewer is being added, and if you do a Get-SCSMRelationshipObject -BySource $RAToModify
on the RA, you will see that it contains the "RAhasReviewer" rel, but not the "ReviewerIsUser" rel, which does exist for other reviewers.
Using this, I thought I was on the verge of a breakthrough, since the -Whatif seemed to understand what I was trying to do, but it choked during actual execution.
So, I guess this is a two part question, the first question above, and maybe if this has happened to anyone else, and how you got that phantom reviewer to stop showing up.
Answers
May it be, that in the template you have an empty reviewer in it? It happened to us after a user was deleted and has been defined as a reviewer in a template. The empty reviewer exists still.
As for the deletion of the reviewer, it should work like this (I tested it in our environment and it worked)
@Daniel_Polivka1 The actual error you are getting is due to an off SMLets quirk.
It assumes you are deleting a Config Item. The CMDLet will set the ObjectStatus to "Pending Delete" in normal mode or actually delete the object if you add the -Force param. (As per Simon's code above).
Because a Reviewer is not a CI and does not have an ObjectStatus property you MUST use -Force which will just delete it. There is no pending delete / recycle bin etc for non CIs.
For the second part of the question - lets find out where it it coming from.
In PowerShell, once you have the Reviewer Object rather than delete it, pipe it to Get-SCSMObjectHistory. This will show you when and who create it.
Was the account that created the SR, or was it the Workflow account?
Was it the same time or a few seconds later?
@Geoff_Ross
Interesting! I have not used Get-SCSMObjectHistory before, lots of cool data in there. I do wonder why SMLets does that, but I'm not losing any sleep over it since Simon's suggestion does the trick.
@Simon_Zeinhofer
THANK YOU. The force is what I was missing. Everything worked perfectly.
Thank you both so much!
Glad to hear it helped :)
because of the empty reviewer, have a deeper look at the template. We also have this issue when a user, who is set as reviewer directly in a template, quits and the SCSM user object gets deleted. Even worse, if a user's username changes and a new object gets created, the old reviewer gets added (although no user is related to it) and the new user objects gets rewritten as non-analyst inside the CI$user table. This seems to be some bug with smlets when applying the scsm object template to a workitem.
Therefor I could imagine your problem might go in the same direction ;)