Norint užtikrinti saugumą ir našumą, labai svarbu nuolat atnaujinti „Windows 11“. Nors galite rankiniu būdu patikrinti „Windows“ naujinimų istoriją, naudojant „PowerShell“ scenarijų galima greičiau ir detaliau peržiūrėti sistemos naujinimo būseną. Šiame straipsnyje bus parodyta, kaip naudoti PowerShell scenarijų norint patikrinti esamą Windows 11 pataisos informaciją ir galimus naujinimus.
„PowerShell“ scenarijus, kurį naudosime, suteikia išsamios informacijos apie „Windows 11“ diegimą, įskaitant:
- Dabartinė OS versija
- OS redagavimas
- OS versijos numeris
- Naujausias įdiegtas naujinimas (su KB numeriu ir informacijos nuoroda)
- Naujausias galimas naujinimas
Šis scenarijus veikia tiek „Windows 11“, tiek „Windows 10“ sistemoms. Pažiūrėkime, kaip juo naudotis.
1 veiksmas:Atidarykite „PowerShell“ kaip administratorių. Dešiniuoju pelės mygtuku spustelėkite mygtuką Pradėti ir meniu pasirinkite „Windows PowerShell (administratorius)“.
2 veiksmas:Nukopijuokite šį „PowerShell“ scenarijų ir išsaugokite jį kaip .ps1 failą (pvz., „Get-WindowsUpdateInfo.ps1“) savo darbalaukyje:
[CmdletBinding()]
Param(
[switch]$ListAllAvailable,
[switch]$ExcludePreview,
[switch]$ExcludeOutofBand
)
$ProgressPreference="SilentlyContinue"
$URI = "https://aka.ms/WindowsUpdateHistory"
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:SOFTWAREMicrosoftWindows NTCurrentVersion' -Name ProductName).ProductName
Try
{
$Version = (Get-ItemProperty 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion' -Name ReleaseID -ErrorAction Stop).ReleaseID
}
Catch
{
$Version = "N/A"
}
$CurrentBuild = (Get-ItemProperty 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion' -Name CurrentBuild).CurrentBuild
$UBR = (Get-ItemProperty 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion' -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]
})
}
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('.') -and $_.outerHTML -notmatch "Preview" -and $_.outerHTML -notmatch "Out-of-band"}
}
ElseIf ($ExcludePreview)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.') -and $_.outerHTML -notmatch "Preview"}
}
ElseIf ($ExcludeOutofBand)
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.') -and $_.outerHTML -notmatch "Out-of-band"}
}
Else
{
$AllAvailable = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')}
}
$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('.') -and $_.outerHTML -notmatch "Out-of-band" -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludePreview)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.') -and $_.outerHTML -notmatch "Preview"} | Select -First 1
}
ElseIf ($ExcludeOutofBand)
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.') -and $_.outerHTML -notmatch "Out-of-band"} | Select -First 1
}
Else
{
$LatestAvailablePatch = $VersionDataRaw | where {$_.outerHTML -match $CurrentWindowsVersion.'OS Build'.Split('.')} | 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
3 veiksmas:Paleiskite scenarijų įvesdami šią komandą PowerShell:
.Get-WindowsUpdateInfo.ps1
Ši komanda parodys dabartinę „Windows“ versiją, versijos numerį ir naujausią įdiegtą naujinimą.
4 veiksmas:Norėdami iš rezultatų neįtraukti peržiūros ir už juostos ribų esančių naujinimų, naudokite šią komandą:
Taip pat žiūrėkite:Gaukite MFA būseną „Microsoft Entra“ ir „PowerShell“.
.Get-WindowsUpdateInfo.ps1 -ExcludePreview -ExcludeOutofBand
Ši parinktis naudinga, jei norite sutelkti dėmesį tik į standartinius kaupiamuosius naujinimus.
5 veiksmas:Norėdami peržiūrėti visus galimus „Windows“ versijos naujinimus, naudokite šią komandą:
.Get-WindowsUpdateInfo.ps1 -ListAllAvailable
Bus rodomas visų „Microsoft“ paskelbtų jūsų konkrečios „Windows“ versijos naujinimų sąrašas.
6 veiksmas:Jei norite matyti visus galimus naujinimus, išskyrus peržiūrą ir išorinius naujinimus, naudokite šią komandą:
.Get-WindowsUpdateInfo.ps1 -ListAllAvailable -ExcludePreview -ExcludeOutofBand
Ši komanda sujungia parinktis, kad pateiktų jums sutelktą standartinių naujinimų sąrašą.
Naudojant šį „PowerShell“ scenarijų supaprastinamas „Windows 11“ naujinimo būsenos tikrinimo procesas. Tai ypač naudinga IT specialistams, tvarkantiems kelias sistemas, arba vartotojams, kurie nori išsamios informacijos apie savo „Windows“ naujinimus neperžiūrėdami kelių meniu.















