โดยปกติ ผู้ใช้ที่ต้องการทราบว่ามีการติดตั้งการอัปเดตแบบสะสมล่าสุดบนระบบ Windows 10 หรือไม่ ใช้วิธีนี้เพื่อตรวจสอบ Windows 10 Update History ในโพสต์นี้ เราจะแสดง วิธีรับข้อมูลแพตช์ปัจจุบันสำหรับ Windows 10 โดยใช้สคริปต์ PowerShell

สคริปต์ PowerShell สำหรับตรวจสอบสถานะ Windows Update
สคริปต์ PowerShell สามารถใช้เพื่อรายงานว่าระบบปฏิบัติการใดที่สร้างคอมพิวเตอร์ Windows 10 อยู่ในปัจจุบัน ตลอดจนการอัปเดตใดเป็นการอัปเดตล่าสุดที่มีให้สำหรับอุปกรณ์ นอกจากนี้ยังสามารถรายงานการอัปเดต Windows ทั้งหมดที่เผยแพร่สำหรับเวอร์ชันของ Windows 10 ที่เวิร์กสเตชันเปิดอยู่
เมื่อคุณเรียกใช้สคริปต์ ข้อมูลต่อไปนี้จะปรากฏขึ้น:
- ระบบปฏิบัติการปัจจุบัน
- รุ่นระบบปฏิบัติการปัจจุบัน
- หมายเลขบิลด์ระบบปฏิบัติการปัจจุบัน
- การอัปเดตที่ติดตั้งซึ่งสอดคล้องกับหมายเลขรุ่นนั้น ตลอดจนหมายเลข KB และลิงก์ไปยังหน้าข้อมูล
- อัปเดตล่าสุดสำหรับระบบปฏิบัติการเวอร์ชัน
หากต้องการรับข้อมูลแพตช์ปัจจุบันของ Windows 10 โดยใช้สคริปต์ PowerShell คุณต้องสร้างและเรียกใช้สคริปต์ PowerShell โดยใช้รหัสด้านล่างจาก Github
[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
คุณยังแสดงรายการอัปเดต Windows ทั้งหมดที่ Microsoft เผยแพร่สำหรับเวอร์ชันระบบปฏิบัติการของคุณได้โดยใช้คำสั่งต่อไปนี้:
Get-CurrentPatchInfo -ListAvailable
หากคุณต้องการยกเว้นการดูตัวอย่างและการอัปเดตนอกวงจากรายการ แต่แสดงรายการการอัปเดต Windows ทั้งหมดที่ Microsoft เผยแพร่สำหรับเวอร์ชันระบบปฏิบัติการของคุณ ให้เรียกใช้คำสั่งด้านล่าง:
Get-CurrentPatchInfo -ListAvailable -ExcludePreview -ExcludeOutofBand
แค่นั้นแหละ!
อ่านต่อ :ไซต์ PowerShell Module Browser ให้คุณค้นหา cmdlets &แพ็คเกจ