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 </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!