简体   繁体   中英

Get software center updates install status from sccm client using powershell

I want to get the real time status of all patches currently in the SCCM Client Software center. I've attempted to use multiple scripts I've found online but none of them end up showing me real time results. I can get all the currently available updates and well as their corresponding software update groups that are deploying those missing patches but have not yet discovered how to link the missing patches to their current status like Software Center currently does.

The function below currently works and is what I use to install the missing patches.

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

I would like to replace:

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

With something showing the patches listed in the sccm software center and their corresponding patch status (Downloading, installing, pending verification, needs reboot, etc...), which the software center shows using its GUI interface.

I can also view any missing updates using a module I wrote that returns one or more missing patches objects. However, the Status for the object can only show Missing or Installed . Not the actual SCCM status of the patch. Example:

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

Software Centre displays progress for software installs and advertisements. It does not show patch status other than Installed/Missing, so I suspect if you want to enumerate the progress status for that patch, you'll need to scrape logs to determine if the client is doing anything with each respective patch to create a calculated status message at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM