Last active
April 17, 2019 14:21
-
-
Save mkht/4b820e5b63c8a7b3133f72e9aab44c24 to your computer and use it in GitHub Desktop.
Show Windows Update History (PowerShell version)
This file contains 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
[CmdletBinding()] | |
Param( | |
[datetime]$DateTo, | |
[datetime]$DateFrom, | |
[switch]$All | |
) | |
# 日本語文字化け対策 | |
$Global:OutputEncoding = [Console]::OutputEncoding | |
if (-not $PSBoundParameters.ContainsKey('DateTo')) { | |
$DateTo = (Get-Date) | |
} | |
if (-not $PSBoundParameters.ContainsKey('DateFrom')) { | |
if ($All) { | |
$DateFrom = [datetime]::MinValue | |
} | |
else { | |
$DateFrom = (Get-Date -Hour 0 -Minute 0 -Second 0) | |
} | |
} | |
if (-not $All) { | |
Write-Warning ('{0}以降にインストールされた更新プログラムのみを取得します' -f $DateFrom.ToString('yyyy/MM/dd')) | |
Write-Warning ('全てのインストール済み更新プログラムを取得する場合は"-All"スイッチを付けて実行してください') | |
} | |
# Search | |
$UpdateSession = New-Object -ComObject Microsoft.Update.Session | |
$Searcher = $UpdateSession.CreateUpdateSearcher() | |
$NumOfHistory = $Searcher.GetTotalHistoryCount() | |
$Updates = $Searcher.QueryHistory(0, $NumOfHistory) |` | |
Where-Object { $_.ResultCode -eq 2 } |` | |
Where-Object { $_.Title -notmatch 'KB2267602' } |` | |
ForEach-Object { | |
$local:InstalledDate = [datetime]$_.Date.ToLocalTime() | |
if (($InstalledDate -lt $DateTo) -and ($InstalledDate -ge $DateFrom)) { | |
$_.Title | |
# $_.Date | |
# $_.Description | |
# $_.ServiceID | |
# $_.SupportUrl | |
# $_.UpdateID | |
# $_.RevisionNumber | |
} | |
} | |
# Output | |
if ($Updates.Count -ge 1) { | |
$Updates | |
if (Get-Command -Name 'Set-Clipboard' -ErrorAction SilentlyContinue) { | |
$Updates | Set-Clipboard | |
} | |
} | |
else { | |
Write-Host ('インストール済み更新プログラムが見つかりませんでした') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment