PowerShellスクリプトを使用してWindows10の現在のパッチ情報を取得する
通常、最新の累積的な更新プログラムがWindows 10システムにインストールされているかどうかを確認したいユーザーは、この方法を使用してWindows10の更新履歴を確認します。この投稿では、PowerShellスクリプトを使用してWindows10の現在のパッチ情報を取得する方法を紹介します。
WindowsUpdateのステータスを確認するためのPowerShellスクリプト
PowerShellスクリプトを使用して、Windows 10コンピューターが現在使用されているOSビルドと、デバイスで利用可能な最新の更新プログラムを報告できます。また、ワークステーションが現在使用しているバージョンのWindows10に対して公開されたすべてのWindowsUpdateについてレポートすることもできます。
スクリプトを実行すると、次の情報が表示されます。
- 現在のOSバージョン
- 現在のOSエディション
- 現在のOSビルド番号
- そのビルド番号に対応するインストール済みのアップデート、KB番号、および情報ページへのリンク
- OSバージョンで利用可能な最新のアップデート
PowerShellスクリプトを使用してWindows10の現在のパッチ情報を取得するには、Githubの以下のコードを使用してPowerShellスクリプトを作成して実行する必要があります。
[CmdletBinding()]
Param(
[switch]$ListAllAvailable,
[switch]$ExcludePreview,
[switch]$ExcludeOutofBand
)
$ProgressPreference = 'SilentlyContinue'
$URI = "https://aka.ms/WindowsUpdateHistory" # Windows 10 release history
Function Get-MyWindowsVersion {
[CmdletBinding()]
Param
(
$ComputerName = $env:COMPUTERNAME
)
$Table = New-Object System.Data.DataTable
$Table.Columns.AddRange(@("ComputerName","Windows Edition","Version","OS Build"))
$ProductName = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ProductName).ProductName
Try
{
$Version = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID -ErrorAction Stop).ReleaseID
}
Catch
{
$Version = "N/A"
}
$CurrentBuild = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name CurrentBuild).CurrentBuild
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
$OSVersion = $CurrentBuild + "." + $UBR
$TempTable = New-Object System.Data.DataTable
$TempTable.Columns.AddRange(@("ComputerName","Windows Edition","Version","OS Build"))
[void]$TempTable.Rows.Add($env:COMPUTERNAME,$ProductName,$Version,$OSVersion)
Return $TempTable
}
Function Convert-ParsedArray {
Param($Array)
$ArrayList = New-Object System.Collections.ArrayList
foreach ($item in $Array)
{
[void]$ArrayList.Add([PSCustomObject]@{
Update = $item.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - ')
KB = "KB" + $item.href.Split('/')[-1]
InfoURL = "https://support.microsoft.com" + $item.href
OSBuild = $item.outerHTML.Split('(OS ')[1].Split()[1] # Just for sorting
})
}
Return $ArrayList
}
If ($PSVersionTable.PSVersion.Major -ge 6)
{
$Response = Invoke-WebRequest -Uri $URI -ErrorAction Stop
}
else
{
$Response = Invoke-WebRequest -Uri $URI -UseBasicParsing -ErrorAction Stop
}
If (!($Response.Links))
{ throw "Response was not parsed as HTML"}
$VersionDataRaw = $Response.Links | where {$_.outerHTML -match "supLeftNavLink" -and $_.outerHTML -match "KB"}
$CurrentWindowsVersion = Get-MyWindowsVersion -ErrorAction Stop
If ($ListAllAvailable)
{
If ($ExcludePreview -and $ExcludeOutofBand)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview" -and $_.outerHTML -notmatch "Out-of-band"}
}
ElseIf ($ExcludePreview)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview"}
}
ElseIf ($ExcludeOutofBand)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band"}
}
Else
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0]}
}
$UniqueList = (Convert-ParsedArray -Array $AllAvailable) | Sort OSBuild -Descending -Unique
$Table = New-Object System.Data.DataTable
[void]$Table.Columns.AddRange(@('Update','KB','InfoURL'))
foreach ($Update in $UniqueList)
{
[void]$Table.Rows.Add(
$Update.Update,
$Update.KB,
$Update.InfoURL
)
}
Return $Table
}
$CurrentPatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'} | Select -First 1
If ($ExcludePreview -and $ExcludeOutofBand)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band" -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludePreview)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludeOutofBand)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0] -and $_.outerHTML -notmatch "Out-of-band"} | Select -First 1
}
Else
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')[0]} | Select -First 1
}
$Table = New-Object System.Data.DataTable
[void]$Table.Columns.AddRange(@('OSVersion','OSEdition','OSBuild','CurrentInstalledUpdate','CurrentInstalledUpdateKB','CurrentInstalledUpdateInfoURL','LatestAvailableUpdate','LastestAvailableUpdateKB','LastestAvailableUpdateInfoURL'))
[void]$Table.Rows.Add(
$CurrentWindowsVersion.Version,
$CurrentWindowsVersion.'Windows Edition',
$CurrentWindowsVersion.'OS Build',
$CurrentPatch.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - '),
"KB" + $CurrentPatch.href.Split('/')[-1],
"https://support.microsoft.com" + $CurrentPatch.href,
$LatestAvailablePatch.outerHTML.Split('>')[1].Replace('</a','').Replace('—',' - '),
"KB" + $LatestAvailablePatch.href.Split('/')[-1],
"https://support.microsoft.com" + $LatestAvailablePatch.href
)
Return $Table インストールしたものよりも新しい利用可能なプレビューまたは帯域外更新を最新の利用可能な更新として報告されないようにすることができるため、以下のコマンドを実行することで累積的な更新に集中できます。
Get-CurrentPatchInfo -ExcludePreview -ExcludeOutofBand
次のコマンドを使用して、MicrosoftがOSバージョン用に公開したすべてのWindowsUpdateを一覧表示することもできます。
Get-CurrentPatchInfo -ListAvailable
プレビューと帯域外の更新をリストから除外したいが、MicrosoftがOSバージョン用に公開したすべてのWindows Updateを一覧表示する場合は、次のコマンドを実行します。
Get-CurrentPatchInfo -ListAvailable -ExcludePreview -ExcludeOutofBand
以上です!
次を読む :PowerShell Module Browserサイトでは、コマンドレットとパッケージを検索できます。
-
Parallels を使用して Mac で Windows を入手するには?
両方のプラットフォームを頻繁に使用する場合、Mac で Windows OS とアプリを使用すると便利です。 Mac はユーザーに敵対的であると言われているため、これがどのように可能であるかを考える必要があります。まあ、それを可能にするアプリがあります。 Mac で Windows を使用する最も一般的な方法の 1 つは、Parallels を使用することです。 Parallels を使用して Mac で Windows を入手する簡単な手順 Mac コンピューターを使用していて、重要な Windows アプリの一部を同じ画面で実行したい場合、Parallels はその目的を解決します。この
-
Windows 10 で Powershell を使用してファイルを圧縮/解凍する方法
ジップ機能 を使用すると、関連するすべての構成を 1 つのファイルに圧縮して、ファイルをより小さいサイズに圧縮できます。このようにして、このような圧縮された Zip ファイルは、電子メールやその他のファイル共有メディアを介して他のユーザーと簡単に共有できます。 Zip 機能を実行するには、ユーザーは通常、WinRAR や 7-zip などの RAR ソフトウェアを使用します。しかし、組み込みの Windows Powershell を使用してファイルを圧縮/解凍することもできることをご存知でしたか?プロセスに取り掛かりましょう– 続きを読む: Windows と Mac でファイルを圧縮す