Powershell system.reviewer

Aug 27, 2011 at 8:23 AM


i am trying to create a powershell script to add a reviewer to an activity.

i'm slowly getting all the info i need, but am struggling with the system.reviewer.

i know i need to use the relationships System.ReviewerIsUser & System.ReviewActivityHasReviewer but i can't seem to allocate a System.Reviewer.

can anyone provide examples of how i would add a reviewer to an activity using powershell please?

many thanks


Aug 29, 2011 at 11:05 PM

Reviewer is a little tricky, because it's got *two* releationships. You need to create a relationship to the review activity to a reviewer and then a relationship from the reviewer to the user. The following script might help you get started, it takes a review activity, a user object and a couple of parameters and creates the correct relationships. This one only allows for adding a reviewer to a review activity. I'll include this script in the next release.




param ( 
    [Parameter(Mandatory=$true,Position=0)]$User ,
        $userClasses = $user.GetLeastDerivedNonAbstractClass().GetBaseTypes()|%{$_.name}
    catch { $userClasses = @() }

    if ( $userClasses -notcontains "System.User" )
        throw "User ($user) must be an instance of a System.User"
    $ACTIVITYHASREVIEWERRELATIONSHIP   = Get-SCSMRelationshipClass System.ReviewActivityHasReviewer
    $REVIEWERISUSERRELATIONSHIP        = Get-SCSMRelationshipClass System.ReviewerIsUser
    if ( $activity.GetLeastDerivedNonAbstractClass().Name -ne "System.WorkItem.Activity.ReviewActivity" )
        throw "Activity ($Activity) must be an instance of a System.WorkItem.Activity.ReviewActivity"
    $reviewerClass = get-scsmclass System.Reviewer
    $reviewerArgs = @{ ReviewerId = "Reviewer{0}" }
    if ( $Comment ) { $reviewerArgs.Comments = $Comment }
    if ( $Veto ) { $reviewerArgs.Veto = $Veto }
    if ( $MustVote ) { $reviewerArgs.MustVote = $true }
    $reviewer = new-scsmobject -class $reviewerClass -prop $reviewerArgs -nocommit
    $ro1 = new-scsmrelationshipobject -nocommit  -Relationship $ACTIVITYHASREVIEWERRELATIONSHIP -sou $activity -tar $reviewer
    $ro2 = new-scsmrelationshipobject -nocommit  -rel $REVIEWERISUSERRELATIONSHIP -Sour $reviewer -targ $user

Aug 30, 2011 at 8:22 AM

Hi Jim,

thanks for the reply, that look like just what i need!

i'd worked out most of it, but just couldn't get the new reviewer object.

i'll give this a go.

thanks again


Nov 8, 2012 at 9:19 PM
Edited Nov 8, 2012 at 9:20 PM

Hi Jim,

I'm having issues while trying to add a new System.ReviewActivityHasReviewer relationship, even with a brand new RA:


PS C:\> New-SCSMRelationshipObject -Relationship $ActivityHasReviewer -Source $RA -Target $ Reviewer -Bulk
New-SCSMRelationshipObject : A discovery data item was rejected because the item is already bound to another Membership relationship.
At line:1 char:27
+ New-SCSMRelationshipObject <<<<  -Relationship $ActivityHasReviewer -Source $RA -Target $Reviewer -Bulk
    + CategoryInfo          : NotSpecified: (:) [New-SCSMRelationshipObject], DiscoveryDataLifetimeDependencyException
    + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.DiscoveryDataLifetimeDependencyException,SMLets.NewSCSMRelationshipObject


I've been using this a lot on my previous job with SCSM 2010... now I'm using 2012 with the latest version of SMLets and it's not working... are you having the same issue?

It's weird that I have no issues while trying to do with the SCSM IP in Orchestrator... but I can't with PowerShell.