Invoke-CimMethod generates an error although it works as expected

I am trying to trigger the installation of updates advertized by SCCM to some computers by invoking a CIM method from Powershell 7. Regardless of the fact that the command triggers the desired action, I still always get the following error message.

Invoke-CimMethod: Es wurde keine Instanz mit den Eigenschaftswerten gefunden.

or the English version:

Invoke-CimMethod : No instance found with given property values.

This is the code:

$COMPUTERNAME = 'RemoteComputer01'
$CIMSession = New-CimSession -ComputerName $COMPUTERNAME
$GetCimInstanceParams = @{
  NameSpace = 'ROOT\ccm\ClientSDK'
  ClassName = 'CCM_SoftwareUpdate'
  Filter = 'ComplianceState = 0'
  CimSession = $CIMSession
  ErrorAction = 'Stop'
}
$InvokeCimMethodParams = @{
  Namespace = 'ROOT\ccm\ClientSDK' 
  ClassName = 'CCM_SoftwareUpdatesManager'
  MethodName = 'InstallUpdates'
  Arguments = @{ CCMUpdates = [ciminstance[]](Get-CimInstance @GetCimInstanceParams) }
  CimSession = $CIMSession
  ErrorAction = 'Stop'
}
Invoke-CimMethod @InvokeCimMethodParams

And it does not matter how I try to invoke the CIM method - “splatted” or “classic” in a single line - I always get the error.

Invoke-CimMethod -Namespace 'root/ccm/ClientSDK' -ClassName 'CCM_SoftwareUpdatesManager' -ComputerName $ComputerName -Arguments @{ CCMUpdates = [ciminstance[]] (Get-CimInstance -Namespace 'root/ccm/ClientSDK' -ClassName 'CCM_SoftwareUpdate' -ComputerName $ComputerName) } -MethodName 'InstallUpdates'

What’s wrong? How do I get rid of the error and get a proper return value?

I already asked this on StackOverflow but I didn’t get any response yet. So if someone is willing to earn 150 credits there … :wink:

https://stackoverflow.com/questions/65705053/error-when-triggering-installation-of-sccm-updates-with-invoke-cimmethod

Thanks in advance

Have you tried to execute this locally from that computer ?

Actually yes and it runs without error. But that’s not what I wanted. I wanted to do it the “proper” way with a cim session and Invoke-CimMethod. :-/

Thanks for your answer anyway. :slight_smile:

Just in case someone else is interested in it in the future …

Eventually found at least a workaround I can live with.

Instead of a CIM session I’m using a PS session now and running the commands actually locally.

$COMPUTERNAME = 'RemoteComputer01'
$PSSession = New-PSSession -ComputerName $COMPUTERNAME
Invoke-Command -Session $PSSession -ScriptBlock {
  $GetCimInstanceParams = @{
    NameSpace = 'ROOT\ccm\ClientSDK'
    ClassName = 'CCM_SoftwareUpdate'
    Filter = 'ComplianceState = 0'
    ErrorAction = 'Stop'
  }
  $InvokeCimMethodParams = @{
    Namespace = 'ROOT\ccm\ClientSDK' 
    ClassName = 'CCM_SoftwareUpdatesManager'
    MethodName = 'InstallUpdates'
    Arguments = @{ CCMUpdates = [ciminstance[]](Get-CimInstance @GetCimInstanceParams ) }
    ErrorAction = 'Stop'
  }
  Invoke-CimMethod @InvokeCimMethodParams
}

This provides me with a proper return code.