Get-SCSMObject : Cannot bind parameter 'Id

alfie thomas 86 Reputation points
2022-05-09T21:23:19.347+00:00

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
Service Manager
Service Manager
A family of System Center products for managing incidents and problems.
209 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 95,411 Reputation points MVP
    2022-05-10T06:55:04.243+00:00

    Hi @ alfiethomas-8724

    please try this:

    Import-Module SMlets
    $smDefaultComputer = "MGMT SERVER"
    $CrID = "CR41111"
    $crClass = Get-SCSMClass -name System.WorkItem.ChangeRequest$
    $thisCR = Get-SCSMObject -Class $crClass -Filter "ID -eq $crID"
    Write-Output "Got CR: $($thisCR.Id)"
    $assignedUserRel = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser
    $createdByRelClass = Get-SCSMRelationshipClass -Name System.WorkItemCreatedByUser
    $createdUser = Get-SCSMRelatedObject -SMObject $thisCR -Relationship $createdByRelClass
    Write-output "Assigning to $($createdUser.displayname)"
    New-SCSMRelationshipObject -Relationship $assignedUserRel -Source $thisCR -Target $createdUser -Bulk
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 44,621 Reputation points
    2022-05-09T21:46:53.797+00:00

    It looks to me to be pretty simple: The cmdlet (or, in this case, a SMLet --whatever that is) wants the -id parameter to have an argument that is a GUID, not a text string that holds the name of something.


  2. 2022-05-11T16:54:03.523+00:00

    thanks alot

    0 comments No comments