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

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of William Anderson William Anderson 2 years, 3 months ago.

  • Author
    Posts
  • #18094
    Profile photo of William Anderson
    William Anderson
    Participant

    Hey there experts!

    First time user of the 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           

    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!

  • #18125
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Your error is described here – 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

  • #18127
    Profile photo of William Anderson
    William Anderson
    Participant

    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!

  • #18140
    Profile photo of William Anderson
    William Anderson
    Participant

    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!

  • #18155
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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

  • #18158
    Profile photo of William Anderson
    William Anderson
    Participant

    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
    

You must be logged in to reply to this topic.