How to use New-SCSMRelationshipObject

Mar 15, 2011 at 9:45 PM

I'm trying to update the CreatedBy on a Change Request... This is what I have:

#getting the CR

$CRClass = Get-SCSMClass -Name System.WorkItem.ChangeRequest$

$ChangeReq = Get-SCSMObject $CRClass|?{$_.Id -eq "CR58"}

#getting the Relationship

$CreatedByRelClass = Get-SCSMRelationshipClass System.WorkItemCreatedByUser$

$props = @{Domain="domain";UserName="user"}

#add the relationship

New-SCSMRelationshipObject -RelationShip $CreatedByRelClass -Properties $props

 

Of course the last line is not working, it may be because I don't know how to actually use it.

Anybody has experience with this?

 

Thanks!

German

Mar 15, 2011 at 10:42 PM

Never mind... I figured out.

Just in case anybody else wants to use it:

$CreatedByRelClass = Get-SCSMRelationshipClass System.WorkItemCreatedByUser$

$CRClass = Get-SCSMClass -Name System.WorkItem.ChangeRequest$

$ChangeReq = Get-SCSMObject $CRClass|?{$_.Id -eq "CR58"}

$UserClass = Get-SCSMClass System.Domain.User$

$CreatedByUser = Get-SCSMObject $UserClass|?{$_.UserName -eq "username"}

$props = @{__Source=$ChangeReq; __Target=$CreatedByUser}

New-SCSMRelationshipObject -RelationShip $CreatedByRelClass -Properties $props

You can also replace the $CreatedByUser by using the Get-User function available on Set-IncidentUser.ps1 from SMLets.