# Invoke-CimMethod generates an error although it works as expected

**URL:** <https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498>\
**Category:** PowerShell Help\
**Created:** [January 18, 2021, 3:06pm UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498 "2021-01-18T15:06:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 18, 2021, 3:06pm UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498/1 "2021-01-18T15:06:48Z")

</div>

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 … 😉

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

Thanks in advance

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [January 19, 2021, 5:04am UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498/2 "2021-01-19T05:04:55Z")

</div>

Have you tried to execute this locally from that computer ?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 19, 2021, 7:40am UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498/3 "2021-01-19T07:40:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 20, 2021, 10:56pm UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498/4 "2021-01-20T22:56:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/invoke-cimmethod-generates-an-error-although-it-works-as-expected/15498/5 "2024-05-16T20:28:00Z")

</div>


