I have some code that uses Invoke-CimMethod to query the registry and the SCCM client for pending reboots. When attempting to query over a CIM session, the registry query works, but the SCCM client query doesn't, without a CIM session, both commands work. Can anyone help me identify what I'm missing. Here is some sample code that reproduces the problem. Example 4, is the one I have issues with ...
# Variables
$hklm = [UInt32]"0x80000002"
$Key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\"
# Set up CIM session
$cimSessionSplat = @{
ComputerName = $env:COMPUTERNAME
ErrorAction = "Stop"
}
$cimSession = New-CimSession @cimSessionSplat
$invokeCimMethodSplatReg = @{
Namespace = "ROOT\CIMv2"
ClassName = "StdRegProv"
MethodName = "EnumValues"
Arguments = @{hDefKey = $hklm; sSubKeyName = $Key}
}
$invokeCimMethodSplatCCM = @{
NameSpace = "ROOT\ccm\ClientSDK"
ClassName = "CCM_ClientUtilities"
MethodName = "DetermineifRebootPending"
}
# Example 1: Query a registry setting (works)
Invoke-CimMethod @invokeCimMethodSplatReg
# Example 2: Query a registry setting (via a CIM session) (works)
$invokeCimMethodSplatReg.CimSession = $cimSession
Invoke-CimMethod @invokeCimMethodSplatReg
# Example 3: Query for ConfigMgr pending reboots (works)
Invoke-CimMethod @invokeCimMethodSplatCCM
# Example 4: Query for ConfigMgr pending reboots (via CIM session) (fails)
$invokeCimMethodSplatCCM.CimSession = $cimSession
Invoke-CimMethod @invokeCimMethodSplatCCM
User contributions licensed under CC BY-SA 3.0