Reputation: 791
The following PowerShell code works locally but I have not been able to convert all of it to use CIM commands. I have been unable to convert the first three queries to CIM. The reason I need to use CIM is because that is how my network currently allows for PowerShell remote access. The test computer has the latest SCCM Client installed.
# Check all locations that would contain a pending reboot flag
$RebootPending = $false
$RebootPending = $RebootPending -or ([wmiclass]'ROOT\ccm\ClientSDK:CCM_ClientUtilities').DetermineIfRebootPending().RebootPending
$RebootPending = $RebootPending -or ([wmiclass]'ROOT\ccm\ClientSDK:CCM_ClientUtilities').DetermineIfRebootPending().IsHardRebootPending
$RebootPending = $RebootPending -or (@(((Get-ItemProperty("HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager")).$("PendingFileRenameOperations")) |
Where-Object { $_ }
).length -ne 0)
$RebootPending = $RebootPending -or (
@(Get-WmiObject -Query "SELECT * FROM CCM_SoftwareUpdate" -Namespace "ROOT\ccm\ClientSDK" |
Where-Object {
$_.EvaluationState -eq 8 -or # patch pending soft reboot
$_.EvaluationState -eq 9 -or # patch pending hard reboot
$_.EvaluationState -eq 10 } # reboot needed before installing patch
).length -ne 0)
I have managed to convert the last query to Cim but I cannot seem to determine how to convert the other three queries to Cim
Converted Query:
$RebootPending = $RebootPending -or (
@(Get-CimInstance -CimSession $($Computer.CimSession) -Namespace 'ROOT\ccm\ClientSDK' -Query "SELECT * FROM CCM_SoftwareUpdate" |
Where-Object {
$_.EvaluationState -eq 8 -or # patch pending soft reboot
$_.EvaluationState -eq 9 -or # patch pending hard reboot
$_.EvaluationState -eq 10 } # reboot needed before installing patch
).length -ne 0
)
Upvotes: 0
Views: 1002
Reputation: 8442
You can use the Invoke-CimMethod
cmdlet if you want to use CIM sessions. For the first two items in your example, call it as follows:
Invoke-CimMethod -ClassName 'CCM_ClientUtilities' `
-CimSession $Computer.CimSession `
-MethodName 'DetermineIfRebootPending' `
-Namespace 'ROOT\ccm\ClientSDK'
You will get an object back like this:
DisableHideTime : 01/01/1970 00:00:00
InGracePeriod : False
IsHardRebootPending : False
NotifyUI : False
RebootDeadline : 01/01/1970 00:00:00
RebootPending : True
ReturnValue : 0
PSComputerName :
For the Get-ItemProperty
example, call it slightly differently:
Invoke-CimMethod -ClassName 'StdRegProv ' `
-CimSession $Computer.CimSession `
-MethodName 'GetMultiStringValue' `
-Namespace 'ROOT\Cimv2' `
-Arguments @{hDefKey=[uint32]2147483650;
sSubKeyName="SYSTEM\CurrentControlSet\Control\Session Manager";
sValueName="PendingFileRenameOperations"}
The output will be an array of strings like this:
sValue
-----
{\??\C:\ProgramData\Microsoft\...
Upvotes: 0