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!

Best Answer

  • Filip_TheyssensFilip_Theyssens Partner IT Monkey ✭
    Accepted Answer

    I removed the credentials because if you do not specify the credentials, the New-PsSession gets created using the current user credentials.

    This was already the workflow account, so I didn't need to put them in the script in clear text.

    Problem solved

Answers

  • Filip_TheyssensFilip_Theyssens Partner IT Monkey ✭

    Hello all,

    When I run the script then the class variable doesn't get populated using the PS Activity.

    If I however run the same script but create a remote-Pssession with the same account to the localhost, then this works..

    I'm really puzzled why it doesn't work when just running the script as opposed to first establishing a 'remote' session on the same host.

    Any ideas would be welcome as I have now clear text credentials in my script.

    Thanks!

  • Filip_TheyssensFilip_Theyssens Partner IT Monkey ✭
    Accepted Answer

    I removed the credentials because if you do not specify the credentials, the New-PsSession gets created using the current user credentials.

    This was already the workflow account, so I didn't need to put them in the script in clear text.

    Problem solved

  • john_doylejohn_doyle Cireson Support Advanced IT Monkey ✭✭✭
    Hi Filip,
    I had a look at the code which reads the parameters defined in the PowerShell script. It only accepts parameters if they are in the format:
    Param([type]$paramName)

    or
    Param([Parameter(Mandatory=$True)][type]$paramName)


    Can you try defining the parameter as:
    Param([string]$ID)




Sign In or Register to comment.