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?
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.