以下PowerShell代码在本地工作,但是我无法将其全部转换为使用CIM命令。我无法将前三个查询转换为CIM。我需要使用CIM的原因是因为这是我的网络当前允许PowerShell远程访问的方式。测试计算机已安装了最新的SCCM客户端。
# 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)
我设法将最后一个查询转换为Cim,但似乎无法确定如何将其他三个查询转换为Cim
转换后的查询:
$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
)
答案 0 :(得分:0)
如果要使用CIM会话,则可以使用Invoke-CimMethod
cmdlet。对于示例中的前两项,请按以下方式调用它:
Invoke-CimMethod -ClassName 'CCM_ClientUtilities' `
-CimSession $Computer.CimSession `
-MethodName 'DetermineIfRebootPending' `
-Namespace 'ROOT\ccm\ClientSDK'
您将像这样获得一个物体:
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 :
对于Get-ItemProperty
示例,将其命名略有不同:
Invoke-CimMethod -ClassName 'StdRegProv ' `
-CimSession $Computer.CimSession `
-MethodName 'GetMultiStringValue' `
-Namespace 'ROOT\Cimv2' `
-Arguments @{hDefKey=[uint32]2147483650;
sSubKeyName="SYSTEM\CurrentControlSet\Control\Session Manager";
sValueName="PendingFileRenameOperations"}
输出将是这样的字符串数组:
sValue
-----
{\??\C:\ProgramData\Microsoft\...