Created
April 16, 2017 14:29
-
-
Save rgl/d124d37ac6e8c5ebe4b3aab0fdf99bfb to your computer and use it in GitHub Desktop.
List Windows update history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = 'Stop' | |
| trap { | |
| Write-Output "ERROR: $_" | |
| Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1') | |
| Exit 1 | |
| } | |
| Write-Output 'Windows update history:' | |
| $updateSearcher = (New-Object -ComObject 'Microsoft.Update.Session').CreateUpdateSearcher() | |
| $updateSearcher.QueryHistory(0, $updateSearcher.GetTotalHistoryCount()) ` | |
| | Where-Object {$_.ResultCode -ne $null} ` | |
| | ForEach-Object { | |
| $result = switch ($_.ResultCode) { | |
| 0 { 'NotStarted' } | |
| 1 { 'InProgress' } | |
| 2 { 'Succeeded' } | |
| 3 { 'SucceededWithErrors' } | |
| 4 { 'Failed' } | |
| 5 { 'Aborted' } | |
| default { $_ } | |
| } | |
| New-Object -TypeName PSObject -Property @{ | |
| Date = $_.Date | |
| By = $_.ClientApplicationID | |
| Result = $result | |
| Title = $_.Title | |
| } | |
| } ` | |
| | Sort-Object -Descending Date ` | |
| | Format-Table -Property Date,Result,By,Title -AutoSize ` | |
| | Out-String -Stream -Width ([int]::MaxValue) ` | |
| | ForEach-Object {$_.TrimEnd()} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment