使用powershell

时间:2018-05-17 19:17:37

标签: powershell sccm patch

我想获取SCCM客户端软件中心当前所有补丁的实时状态。我试图使用我在网上找到的多个脚本,但没有一个脚本最终显示我的实时结果。我可以获得所有当前可用的更新以及正在部署这些缺失补丁的相应软件更新组,但尚未发现如何将缺失的补丁链接到当前状态,如软件中心当前所做的那样。

以下功能目前有效,是我用来安装缺失的补丁。

Function Install-SCCMPatchesAvailable {
  [CmdletBinding()]
  param(
    [Parameter(
      Position = 0,
      Mandatory = $false,
      ValueFromPipelineByPropertyName = $true,
      HelpMessage = "Do not reboot server after patches install")]
    [ValidateNotNullOrEmpty()]
    [switch]
    $DoNotReboot
  )

  begin {
    Write-Verbose "Install-SCCMPatchesAvailable: Started"
  }

  process {
    try {
      ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates([System.Management.ManagementObject[]] `
        (Get-WmiObject -Query 'SELECT * FROM CCM_SoftwareUpdate' -namespace 'ROOT\ccm\ClientSDK'))

      while (-not((Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).DetermineIfRebootPending().RebootPending)) {
        $Time = (get-date).ToShortTimeString()
        Write-Output "Still Patching @ $Time"
        Start-Sleep -s 60
      }
      if (-not $PSBoundParameters.ContainsKey('DoNotReboot')) {
        if ((Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).DetermineIfRebootPending().RebootPending) {
          (Get-WmiObject -Namespace 'ROOT\ccm\ClientSDK' -Class 'CCM_ClientUtilities' -list).RestartComputer()
        }
      }
    }
    catch {
      Write-Error -Message "Something went wrong with Install-SCCMPatchesAvailable.`n`nError.Exception.Message : $($_.Exception.Message)`nError.Exception.FullName: $($_.Exception.GetType().FullName)"
    }
  }

  end {
    Write-Verbose "Install-SCCMPatchesAvailable: Completed"
  }
} #End Install-SCCMPatchesAvailable

我想替换:

$Time = (get-date).ToShortTimeString()
Write-Output "Still Patching @ $Time"
Start-Sleep -s 60

显示sccm软件中心列出的补丁及其相应的补丁状态(下载,安装,待验证,需要重启等),软件中心使用其GUI界面显示补丁。

我还可以使用我编写的模块查看任何缺少的更新,该模块返回一个或多个缺少的补丁对象。但是,对象的Status只能显示MissingInstalled。不是补丁的实际SCCM状态。例如:

SCCMPatchDeploymentName  : .MS_Server_Engineering_Patch_Testing - Post Basline OSs QAC 
                           Testing
ComputerName             : FSL04231
__GENUS                  : 2
__CLASS                  : CCM_UpdateStatus
__SUPERCLASS             : 
__DYNASTY                : CCM_UpdateStatus
__RELPATH                : CCM_UpdateStatus.UniqueId="5dc25e3e-31b9-4ac7-b1b7-a62a982139
                           0d"
__PROPERTY_COUNT         : 15
__DERIVATION             : {}
__SERVER                 : FSL04231
__NAMESPACE              : ROOT\ccm\SoftwareUpdates\UpdatesStore
__PATH                   : \\FSL04231\ROOT\ccm\SoftwareUpdates\UpdatesStore:CCM_UpdateSt
                           atus.UniqueId="5dc25e3e-31b9-4ac7-b1b7-a62a9821390d"
Article                  : 4088787
Bulletin                 : 
ExcludeForStateReporting : False
Language                 : 
ProductID                : 0fa1201d-4330-4fa8-8ae9-b877473b6441
RevisionNumber           : 202
ScanTime                 : 20180516214114.000000+000
Sources                  : {{7D052A75-2032-4F02-BAC9-9EDA4DBD58DE}}
SourceType               : 2
SourceUniqueId           : {7D052A75-2032-4F02-BAC9-9EDA4DBD58DE}
SourceVersion            : 82
Status                   : Missing
Title                    : 2018-03 Cumulative Update for Windows Server 2016 for 
                           x64-based Systems (KB4088787)
UniqueId                 : 5dc25e3e-31b9-4ac7-b1b7-a62a9821390d
UpdateClassification     : 0fa1201d-4330-4fa8-8ae9-b877473b6441
PSComputerName           : FSL04231

1 个答案:

答案 0 :(得分:0)

软件中心显示软件安装和广告的进度。它不会显示已安装/缺失以外的补丁状态,因此我怀疑如果要枚举该补丁的进度状态,您需要抓取日志以确定客户端是否正在对每个相应的补丁创建任何内容以创建运行时计算出的状态消息。