代码之家  ›  专栏  ›  技术社区  ›  Keith

将本地PowerShell命令转换为用于远程管理的CIM实例

  •  0
  • Keith  · 技术社区  · 6 年前

    以下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
    )
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   boxdog    6 年前

    Invoke-CimMethod

    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\...