question

alfiethomas-8724 avatar image
0 Votes"
alfiethomas-8724 asked 50097755 answered

Get-SCSMObject : Cannot bind parameter 'Id

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

windows-server-powershellmsc-service-manager
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered alfiethomas-8724 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Rich.

Definitely wants the 16 digit GUID of the change and have actually been able to get that working now manually if i enter the guid of a certain change it runs.. Updates the Assigned to user to match the afftected user.

IIt's just how I push through the GUID of each new change that is created so it runs each time.

Regards

0 Votes 0 ·
50097755 avatar image
0 Votes"
50097755 answered

thanks alot

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.