0

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

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

or translated to English:

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 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 return value?

Olaf
  • 4,690
  • 2
  • 15
  • 23

2 Answers2

1

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.

Olaf
  • 4,690
  • 2
  • 15
  • 23
0

Same issue with PowerShell 5, I updated my code to ignore the error

[ciminstance[]]$Application = (Get-CIMinstance -CIMSession $CIMsession -Namespace "root\ccm\clientSDK" -Class CCM_SoftwareUpdate | Where-Object { $_.EvaluationState -like "*$($AppEvalState0)*" -or $_.EvaluationState -like "*$($AppEvalState1)*"})

Invoke-CimMethod -Namespace root\ccm\clientsdk -ClassName CCM_SoftwareUpdatesManager -MethodName 'InstallUpdates' -Arguments @{CCMUpdates = $Application} -CimSession $CIMsession -ErrorAction SilentlyContinue |out-null

if($error[0] -notlike "*no instance found*"){
     Write-log "Error found $($error)"
}