PowerShell-script om de Windows Update-status te controleren
Gewoonlijk gebruiken gebruikers die willen weten of de nieuwste cumulatieve update op hun Windows 10-systeem is geïnstalleerd, deze methode om de Windows 10 Update-geschiedenis te controleren . In dit bericht laten we u zien hoe u actuele patchinformatie voor Windows 10 kunt krijgen met behulp van een PowerShell-script.(how to get current patch information for Windows 10 using a PowerShell script.)

PowerShell- script om de Windows Update- status te controleren
Het PowerShell- script kan worden gebruikt om te rapporteren op welke OS-build een Windows 10 -computer zich momenteel bevindt en welke update de nieuwste update is die beschikbaar is voor het apparaat. Het kan ook rapporteren over alle Windows -updates die zijn gepubliceerd voor de versie van Windows 10 waarop een werkstation momenteel staat.
Wanneer u het script uitvoert, wordt de volgende informatie weergegeven:
- Huidige OS-versie
- Huidige OS-editie
- Huidig OS-buildnummer
- De geïnstalleerde update die overeenkomt met dat buildnummer, evenals het KB-nummer en een link naar de infopagina
- De laatst beschikbare update voor de OS-versie
Om de huidige patch-informatie van Windows 10 te krijgen met behulp van het (Windows 10)PowerShell - script, moet u het PowerShell-script maken en uitvoeren(create and run the PowerShell script) met behulp van de onderstaande code van 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
U kunt uitsluiten dat Preview- of Out-of-band- updates die recenter zijn dan degene die u hebt geïnstalleerd, worden gerapporteerd als de nieuwste beschikbare update, zodat u zich kunt concentreren op de cumulatieve updates door de onderstaande opdracht uit te voeren:
Get-CurrentPatchInfo -ExcludePreview -ExcludeOutofBand
U kunt ook alle Windows -updates weergeven die Microsoft voor uw OS-versie heeft gepubliceerd met de volgende opdracht:
Get-CurrentPatchInfo -ListAvailable
Als u Preview- en Out-of-band- updates van de lijst wilt uitsluiten, maar alle Windows - updates wilt weergeven die Microsoft heeft gepubliceerd voor uw OS-versie, voert u de onderstaande opdracht uit:
Get-CurrentPatchInfo -ListAvailable -ExcludePreview -ExcludeOutofBand
Dat is het!
Volgende lezen(Read next) : PowerShell Module Browser-site laat u zoeken naar cmdlets en pakketten.
Related posts
Reset Windows Update Client met PowerShell Script
Knop Problemen oplossen op de Windows Update-pagina
Best practices om de installatietijden van Windows Update te verbeteren
Waar te vinden en hoe het Windows Update-logboek te lezen in Windows 11/10
Hoe Windows Update-fout 0x80240061 op te lossen?
Windows Update loopt vast bij het downloaden van updates in Windows 11/10
Windows Update- en beveiligingsinstellingen in Windows 10
Kan Windows Update niet installeren met foutcode 0x8024200D
Windows Update-fouten 0x800705b4, 0x8024402f of 0x8024002e [opgelost]
Hoe u Windows Update-fout 0xc1900201 kunt oplossen
Fix Windows Update-fout 0x8e5e03fa op Windows 10
Fix Windows Update-fout 0x80070541 op Windows 10
Windows Update-fout 0x800B0101, er is een fout opgetreden in het installatieprogramma
Nieuwe functies in Windows 10 versie 20H2 Update oktober 2020
Andere Microsoft-producten bijwerken met Windows Update
Fix Windows Update Error 0x800f0989 op Windows 11/10
Hoe u Windows Update-foutcode 80244010 kunt oplossen
Fix De Windows Update-service kon niet worden gestopt
Fix Windows Update-fout 0x80070422 op Windows 10
Windows blijft dezelfde update aanbieden of installeren
