SCSM and PowerShell

Hi

I am trying to change a runbook activity status in SCSM to failed using the below command in PowerShell:

Set-SCSMObject -SMObject $Object -Property Status -Value "Failed"

But I get the below error when I run it:

Set-SCSMObject : Unable to cast object of type 'System.String' to type 'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject'.

Does anyone know how to fix it? Or what is wrong in that code block?

Any help will be appreciated.

Thanks

September 3rd, 2015 2:36am

Nothing seems wrong with the code block, but can you show the code for how $Object is set? This needs to be an EnterpriseManagementObject not a string.

Example:

$Object = get-scsmobject -class (get-scsmclass -Name System.workitem.incident$) -filter "Id -eq IR42"

Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 8:43am

I am manually assigning a Runbook ID to $Object to test for now. e.g $Object = RB12345

Then I am trying to test if the Set-SCSMObject changes the status of that activity to failed.

September 6th, 2015 9:15pm

Ok but in that case the Runbook ID is still of type system.string.

There are probably several ways to do this, but one way could be:

$Object = get-scsmobject -Id {ObjectGUID from runbook retrieved}
Where you subscribe to the published data - ObjectGUID of the activity where you are getting the runbook activity.


Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 12:16pm

Hi,

Here's a codesample to set a specific RBA status to Failed:

Import-Module SMLets
$RBAClass = Get-SCSMClass Microsoft.SystemCenter.Orchestrator.RunbookAutomationActivity$
$RBA = Get-SCSMObject -Class $RBAClass -Filter "Id -eq RB13788"
$ActivityStatusFailedEnum = Get-SCSMEnumeration ActivityStatusEnum.Failed$

Set-SCSMObject -SMObject $RBA -Property Status -Value $ActivityStatusFailedEnum

Regards
//Anders

September 7th, 2015 2:51pm

Do you think this should work? I am getting an error: Cannot bind argument to parameter 'Class' because it is null. for Get-SCSM Object.

$RBID = "RB21286"
$RBAClass = Get-SCSMClass Microsoft.SystemCemter.Orchestrator.RunbookAutomationActivity$
$RBA = Get-SCSMObject -Class $RBAClass -Filter "Id -eq $RBID"
$ActivityStatusFailedEnum = Get-SCSMEnumeration ActivityStatusEnum.Failed$

I am getting $RBID from initialise data runbook activity in my runbook. And the script will go into a run.net Activity.

Thanks

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 8:14pm

I think the error means the $RBAClass is null. does that mean, it did not have any $RBAs to filter from?
September 7th, 2015 9:01pm

Okay. Finally got it working now. Thanks Anders :)
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 9:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics