Hi Guys,
Trying to run this in a runbook. Monitor new Change requests and then run this PowerShell.
Want it to update the Assigned to user to matched the created by but getting the below errors. I know it's around the ID I am passing through but not sure how to pass the GUID through via this or orchestrator. Any Ideas?
Thanks.
Import-Module SMlets
$smDefaultComputer = "MGMT SERVER"
$CrID = "CR41111"
$crClass = Get-SCSMClass -name System.WorkItem.ChangeRequest$
$thisCR = Get-SCSMObject -id $CrID
Write-Output "Got CR: $($thisCR.Id)"
$assignedUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
$createdByRelClass = Get-SCSMRelationshipClass -Name System.WorkItemCreatedByUser
$createdRelationship = Get-SCSMRelationshipObject -BySource $thisCR | ?{$.relationshipid -eq $createdByRelClass.id -and $.sourceobject.classname -eq $crClass.Name}
$createdUser = Get-SCSMObject -id $createdRelationship.TargetObject.Id
Write-output "Assigning to $($createdUser.displayname)"
New-SCSMRelationshipObject -Relationship $assignedUserRel -Source $thisCR -Target $createdUser -Bulk
ERRORS:
Get a specific Incident Request
Get-SCSMObject : Cannot bind parameter 'Id'. Cannot convert value "CR415522" to type "System.Guid". Error: "Guid should contain 32 digits with 4 dashes
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
At line:9 char:30
- $thisCR = Get-SCSMObject -id $CrID
- ~~~~~
- CategoryInfo : InvalidArgument: (:) [Get-SCSMObject], ParameterBindingException
- FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.GetSMObjectCommand
Got CR:
Get-SCSMRelationshipObject : Cannot bind argument to parameter 'BySource' because it is null.
At line:17 char:61
- ... edRelationship = Get-SCSMRelationshipObject -BySource $thisCR | ?{$_. ...
- ~~~~~~~
- CategoryInfo : InvalidData: (:) [Get-SCSMRelationshipObject], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SMLets.GetSCSMRelationshipObjectCommand
Get-SCSMObject : Cannot bind argument to parameter 'Id' because it is null.
At line:19 char:35
- ... createdUser = Get-SCSMObject -id $createdRelationship.TargetObject.Id
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Get-SCSMObject], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SMLets.GetSMObjectCommand
Assigning to
New-SCSMRelationshipObject : Cannot bind argument to parameter 'Source' because it is null.
At line:23 char:67
- ... tionshipObject -Relationship $assignedUserRel -Source $thisCR -Target ...
- ~~~~~~~
- CategoryInfo : InvalidData: (:) [New-SCSMRelationshipObject], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SMLets.NewSCSMRelationshipObject