Cannot retrieve classes

Filip_TheyssensFilip_Theyssens Partner IT Monkey ✭
edited April 19 in Powershell Activity

Hello All,

I'm exploring the Powershell Activity to dynamically update the title on our Service Requests.

I've created a powershell script that looks like the following:

param ($ID)

ipmo smlets
$SrClass=get-scsmclass -ComputerName SCSM01a -Name System.WorkItem.ServiceRequest$
$SR=Get-SCSMObject -ComputerName SCSM01a -Class $SrClass | where {$_.Name -eq $ID}
$Title=$SR.Title
[xml]$xml=$sr.userinput
$Answer=$xml.UserInputs.userinput.answer


$Title="$Title ($Answer)"
$PropertyHash = @{"Title"=$($Title)}
$SR | Set-SCSMObject -ComputerName SCSM01a -PropertyHashtable $PropertyHash

When I run this manually this works off course, but when ran through the PS activity, I get the following:

An error was written to the Error stream!
Cannot bind argument to parameter 'Class' because it is null.
An error was written to the Error stream!
Cannot bind argument to parameter 'Class' because it is null.Cannot bind argument to parameter 'SMObject' because it is null.

It seems as if my $SRClass variable can't be populated while the syntax is correct.

I checked and the script gets executed under the workflow account which has all the rights it needs on the server & within scsm.

I also tried capturing the error stream, but this doesn't provide much more info to me:

<?xml version="1.0"?>
<Objects>
  <Object Type="System.Management.Automation.ErrorRecord">
    <Property Name="PSMessageDetails" Type="System.Object" />
    <Property Name="Exception" Type="System.Management.Automation.ParameterBindingValidationException">System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Class' because it is null.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)</Property>
    <Property Name="TargetObject" Type="System.Object" />
    <Property Name="CategoryInfo" Type="System.Management.Automation.ErrorCategoryInfo">InvalidData: (:) [Get-SCSMObject], ParameterBindingValidationException</Property>
    <Property Name="FullyQualifiedErrorId" Type="System.String">ParameterArgumentValidationErrorNullNotAllowed,SMLets.GetSMObjectCommand</Property>
    <Property Name="ErrorDetails" Type="System.Management.Automation.ErrorDetails" />
    <Property Name="InvocationInfo" Type="System.Management.Automation.InvocationInfo">System.Management.Automation.InvocationInfo</Property>
    <Property Name="ScriptStackTrace" Type="System.String">at &lt;ScriptBlock&gt;, &lt;No file&gt;: line 12</Property>
    <Property Name="PipelineIterationInfo" Type="System.Collections.ObjectModel.ReadOnlyCollection`1[System.Int32]" />
  </Object>
</Objects>


Anybody have an idea?

thanks!

Sign In or Register to comment.