PowerShell for SCSM: Remove and Add Reviewers to In Progress Change Requests
Why do you want to do this?
Sometimes you need to update the Reviewers on all active Review Activities, that is add or remove
reviewers from the RA. This came up in one of the TechNet Forum questions and I developed this script as a result. It could easily be adapted to update activities on a Service Request or with a bit of work to support updating manual activates just as easily.
What does it do?
The script gets all the current In Progress Changes and then loops through the each of them to look for Review Activities. It then loops through each Review Activity and gets the existing reviewers. It then checks to see if it is a reviewer it should remove and then finally adds the new reviewer.
Find all changes that are in progress
Loops through each Change
Get review activities on each change
Loops through each Review Activity
Get the reviewers on each Review Activity
Loops through each reviewer
Checks the Reviewer and removes them if they matches the Remove user
Checks to see if the Add user is already on the Review Activity
Finishes loop through Reviewers
Adds the User to the Review Activity (only if not already added)
Finishes loop through Review Activities
Finishes loop through In Progress Activities
High Level Explanation of the Script First as always define the variables, classes and relationships to be used.
The first step is to find all Changes that are In Progress. In Progress is a list value from Change Status. To filter on this it is best to have the Enumeration (Enum) value. One way to get this is to get the list of Enums for the Change Status:
Get-SCSMEnumeration -name ChangeStatusEnum | FL
From this we can get the ID value to use as the filter in Get-SCSMobject command.
We now start the first of the loops going through each Change to get the Review Activities (regardless of status - completed, pending or In progress). They key at this point is to recursively go through all activities as the Review Activity may be a few levels down under Parallel Activities. We can filter on the class type for Review Activities.
Now we have the Review Activities on the Change, we can look at the Reviewers. So again we get the Reviewers and then loop through them checking to see if they match either of our users. We remove the appropriate users from the Review Activity and check if the add user is already there.
We finish the Reviewers loop and then add the new Reviewer if they were not already on the Review Activity. Note you might want to confirm the Reviewer options (Must Vote, Veto) as they are set to false.
Note: I have used the display name to get user SCSM objects and have assumed this is unique.
Download Script: AddReviewerstoChangeRequest.zip
Xapity PowerShell Activity The Xapity PowerShell Activity is an Activity for SCSM that enables PowerShell scripts to be run in SCSM. Automate more of your processes directly in SCSM. Scripts are stored and updated from a central script repository. The scripts execution output can be viewed and if a failure occurs, an email notification can be sent.
Xapity - Innovative Software for SCSM - Discover our Products