Comment vérifier l'état de la mise à jour de Windows 11 avec PowerShell

Garder Windows 11 à jour est crucial pour la sécurité et les performances. Bien que vous puissiez vérifier manuellement l'historique de mise à jour Windows, l'utilisation d'un script PowerShell offre un moyen plus rapide et plus détaillé d'afficher l'état de mise à jour de votre système. Cet article vous montrera comment utiliser un script PowerShell pour vérifier vos informations de correctif Windows 11 actuelles et les mises à jour disponibles.

Le script PowerShell que nous utiliserons fournit des informations complètes sur votre installation de Windows 11, notamment :

  • Version actuelle du système d'exploitation
  • OS edition
  • Numéro de version du système d'exploitation
  • Dernière mise à jour installée (avec numéro de base de connaissances et lien d'information)
  • Mise à jour disponible la plus récente

Ce script fonctionne pour les systèmes Windows 11 et Windows 10. Voyons comment l'utiliser.

Étape 1 :Ouvrez PowerShell en tant qu'administrateur. Cliquez avec le bouton droit sur le bouton Démarrer et sélectionnez « Windows PowerShell (Administrateur) » dans le menu.

Étape 2 :Copiez le script PowerShell suivant et enregistrez-le en tant que fichier .ps1 (par exemple, « Get-WindowsUpdateInfo.ps1 ») sur votre bureau :

[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

Étape 3 :Exécutez le script en entrant la commande suivante dans PowerShell :

.Get-WindowsUpdateInfo.ps1

Cette commande affichera votre version actuelle de Windows, votre numéro de build et la dernière mise à jour installée.

Étape 4 :Pour exclure l'aperçu et les mises à jour hors bande des résultats, utilisez cette commande :

Voir aussi :Obtenez le statut MFA dans Microsoft Entra et PowerShell

.Get-WindowsUpdateInfo.ps1 -ExcludePreview -ExcludeOutofBand

Cette option est utile si vous souhaitez vous concentrer uniquement sur les mises à jour cumulatives standards.

Étape 5 :Pour afficher toutes les mises à jour disponibles pour votre version de Windows, utilisez la commande suivante :

.Get-WindowsUpdateInfo.ps1 -ListAllAvailable

Cela vous montrera une liste de toutes les mises à jour publiées par Microsoft pour votre version spécifique de Windows.

Étape 6 :Si vous souhaitez voir toutes les mises à jour disponibles, à l'exception des mises à jour d'aperçu et hors bande, utilisez cette commande :

.Get-WindowsUpdateInfo.ps1 -ListAllAvailable -ExcludePreview -ExcludeOutofBand

Cette commande combine les options pour vous donner une liste ciblée de mises à jour standard.

L'utilisation de ce script PowerShell simplifie le processus de vérification de l'état de votre mise à jour Windows 11. Il est particulièrement utile pour les professionnels de l'informatique gérant plusieurs systèmes ou pour les utilisateurs qui souhaitent des informations détaillées sur leurs mises à jour Windows sans naviguer dans plusieurs menus.

Related Posts