# Invoke-CimMethod Executes Correct, But Returns WMI Error 0x8004101e

**URL:** <https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984>\
**Category:** PowerShell Help\
**Created:** [August 18, 2014, 1:12am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984 "2014-08-18T01:12:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcse4me2](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mcse4me2](https://forums.powershell.org/u/mcse4me2)\
**Post date:** [August 18, 2014, 1:12am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/1 "2014-08-18T01:12:21Z")

</div>

Hey there experts!

First time user of the [Powershell.org](http://Powershell.org) forums here, and I’ve got a head scratcher for you!

I’m building a module to allow my admins to remotely trigger SCCM Client actions, and it’s triggering the action on the client just fine, but in my PowerShell window, it returns the following error:

```
Invoke-CimMethod : The WS-Management service cannot process the request. The WMI service or the WMI provider returned an unknown error: HRESULT 0x8004101e
At C:\Users\person\Documents\WindowsPowerShell\Modules\Get-CMCommand\Get-CMCommand.psm1:39 char:21
+ Invoke-CimMethod -ClassName SMS_Client -Arguments @{ sSched ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (root/ccm:SMS_Client:String) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : HRESULT 0x8004101e,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName : tehcomputer
```

Here’s the code for review:

```
Function Invoke-CMCommand{
    <#
    .Synopsis
       Invoke Methods on a SCCM Client for a system or systems.
    .DESCRIPTION
       See Synopsis
    .EXAMPLE
       Invoke-CMClientAction -ComputerName -Action HardwareInv

       The above command will invoke the Configuration Manager Client's Hardware Inventory Cycle on the targeted computer.

    .EXAMPLE
       Another example of how to use this cmdlet
    #>

    PARAM(
            [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
            [string[]]$ComputerName,

            [Parameter(Mandatory=$True)]
            [ValidateSet('HardwareInv','SoftwareInv','UpdateScan','MachinePol','UserPolicy')]
            [string]$Action

            )#Close Param

    #$Action...actions...actions...
    SWITCH ($action) {
                        'HardwareInv' {$_action = "{00000000-0000-0000-0000-000000000001}"}
                        'SoftwareInv' {$_action = "{00000000-0000-0000-0000-000000000002}"}
                        'UpdateScan' {$_action = "{00000000-0000-0000-0000-000000000108}"}
                        'MachinePol' {$_action = "{00000000-0000-0000-0000-000000000021}"}
                        'UserPolicy' {$_action = "{00000000-0000-0000-0000-000000000027}"}
                        } #switch
    

            FOREACH ($Computer in $ComputerName){
                if ($PSCmdlet.ShouldProcess("$action $computer")) {
                    
                    Invoke-CimMethod -ClassName SMS_Client -Arguments @{ sScheduleID = $_action } `
                        -MethodName TriggerSchedule -ComputerName $Computer `
			            -Namespace root/ccm
                                        
                }#if
            }#End FOREACH Statement
   
            
    }#Close Function Invoke-HardwareInv
```

If I run the Invoke-CimMethod on it’s own, I get the same error - unless I wrap it in an Invoke-Command -scriptblock. If performed that way, I get a valid return:

Command:

```
Invoke-Command -ComputerName tehcomputer -ScriptBlock { Invoke-CimMethod -ClassName SMS_Client -Arguments @{ sScheduleID = ‘{00000000-0000-0000-0000-000000000108}’ } `
-MethodName TriggerSchedule `
-Namespace root/ccm}
```

Return:

```
ReturnValue PSComputerName RunspaceId

* * *

```
                                              tehcomputer 35e4e272-c2cd-4a04-ac02-42cc9ef8ff39 </pre>

```

In either case, regardless if my script returns an error or not, I get acknowledgement of the command initiating in my SMSClientMethodProvider.log:  
Triggering schedule {00000000-0000-0000-0000-000000000108} SmsClientMethodProvider 8/18/2014 10:37:05 AM 2252 (0x08CC)  
Schedule successfully sent. SmsClientMethodProvider 8/18/2014 10:37:05 AM 2252 (0x08CC)

Am I missing something obvious here? Thanks in advance for taking a look!
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [August 18, 2014, 11:33pm UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/2 "2014-08-18T23:33:03Z")

</div>

Your error is described here - [http://msdn.microsoft.com/en-us/library/aa394559(v=vs.85).aspx](http://msdn.microsoft.com/en-us/library/aa394559(v=vs.85).aspx)

The error description is: User requested an illegal operation, such as spawning a class from an instance.

Couple of questions

What version of WSMAN & PowerShell on the remote system?

Can you try using Invoke-Wmimethod rather than the CIM cmdlet & report any error messages. Thanks

---

<div class="post-metadata">

**Author:** ![mcse4me2](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mcse4me2](https://forums.powershell.org/u/mcse4me2)\
**Post date:** [August 18, 2014, 11:47pm UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/3 "2014-08-18T23:47:32Z")

</div>

Thanks for the reply Richard.

Remote system is as follows:

Name Value

* * *

PSVersion 4.0  
WSManStackVersion 3.0  
SerializationVersion 1.1.0.1  
CLRVersion 4.0.30319.34014  
BuildVersion 6.3.9600.17090  
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}  
PSRemotingProtocolVersion 2.2

I did see that article, but it didn’t really give me a direction to go in as far as troubleshooting goes. I’ll rewrite it with the Invoke-WMIMethod and update this with the results. Thanks again!

---

<div class="post-metadata">

**Author:** ![mcse4me2](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mcse4me2](https://forums.powershell.org/u/mcse4me2)\
**Post date:** [August 19, 2014, 1:37am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/4 "2014-08-19T01:37:29Z")

</div>

Not surprisingly, you were correct sir! Invoke-WMIMethod works just fine:

```
PS C:\windows\system32> Invoke-CMClient -ComputerName tehcomputer -Action UpdateScan

__GENUS : 1
__CLASS :__ PARAMETERS
__SUPERCLASS :
__DYNASTY :__ PARAMETERS
__RELPATH :__ PARAMETERS
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER : TEHCOMPUTER
__NAMESPACE : ROOT\ccm
__PATH : \\TEHCOMPUTER\ROOT\ccm:__ PARAMETERS
ReturnValue :
PSComputerName : TEHCOMPUTER
```

So would the issue with using the CIM Method be a bug or by design do you think? I just wonder if I should submit a bug request or feature request to the SCCM team.

Thanks again kind sir!

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [August 19, 2014, 4:13am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/5 "2014-08-19T04:13:53Z")

</div>

This is a weird one

By default the CIM cmdlets use WSMAN to communicate with a remote computer & your remote machine is using PS 4 which is good for CIM. The WMI cmdlets use DCOM

If you have time could you try an experiment please.

$computer =

$sessw = New-CimSession -ComputerName $computer  
Invoke-CimMethod -Cimsession $sessw -ClassName SMS\_Client -Arguments @{ sScheduleID = $\_action } -MethodName TriggerSchedule -Namespace root/ccm

$opt = New-CimSessionOption -Protocol DCOM  
$sessd = New-CimSession -ComputerName $computer -SessionOption $opt  
Invoke-CimMethod -Cimsession $sessd -ClassName SMS\_Client -Arguments @{ sScheduleID = $\_action } -MethodName TriggerSchedule -Namespace root/ccm

I’m just intrigued as to what’s happening here

---

<div class="post-metadata">

**Author:** ![mcse4me2](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mcse4me2](https://forums.powershell.org/u/mcse4me2)\
**Post date:** [August 19, 2014, 4:57am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/6 "2014-08-19T04:57:10Z")

</div>

Hey there Richard,

Here’s the result and the script.

```
PS C:\windows\system32> $computer = "tehcomputer"

    SWITCH ($action) {
                        'HardwareInv' {$_action = "{00000000-0000-0000-0000-000000000001}"}
                        'SoftwareInv' {$_action = "{00000000-0000-0000-0000-000000000002}"}
                        'UpdateScan' {$_action = "{00000000-0000-0000-0000-000000000108}"}
                        'MachinePol' {$_action = "{00000000-0000-0000-0000-000000000021}"}
                        'UserPolicy' {$_action = "{00000000-0000-0000-0000-000000000027}"}
                        } #switch

$sessw = New-CimSession -ComputerName $computer
Invoke-CimMethod -Cimsession $sessw -ClassName SMS_Client -Arguments @{ sScheduleID = $_action } -MethodName TriggerSchedule -Namespace root/ccm

$opt = New-CimSessionOption -Protocol DCOM
$sessd = New-CimSession -ComputerName $computer -SessionOption $opt
Invoke-CimMethod -Cimsession $sessd -ClassName SMS_Client -Arguments @{ sScheduleID = $_action } -MethodName TriggerSchedule -Namespace root/ccm
Invoke-CimMethod : The WS-Management service cannot process the request. The WMI service or the WMI provider returned an unknown error: HRESULT 0x8004101e 
At line:12 char:1
+ Invoke-CimMethod -Cimsession $sessw -ClassName SMS_Client -Arguments @{ sSchedu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (root/ccm:SMS_Client:String) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : HRESULT 0x8004101e,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName : tehcomputer
 
Invoke-CimMethod : Not found 
At line:16 char:1
+ Invoke-CimMethod -Cimsession $sessd -ClassName SMS_Client -Arguments @{ sSchedu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (root/ccm:SMS_Client:String) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName : tehcomputer
```

---

<div class="post-metadata">

**Author:** ![thom-schumacher](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/thom-schumacher/32/257_2.png) [@thom-schumacher](https://forums.powershell.org/u/thom-schumacher)\
**Post date:** [May 2, 2018, 10:53am UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/7 "2018-05-02T10:53:09Z")

</div>

Were you able to find a solution to this issue?

---

<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:35pm UTC](https://forums.powershell.org/t/invoke-cimmethod-executes-correct-but-returns-wmi-error-0x8004101e/2984/8 "2024-05-16T20:35:06Z")

</div>


