Habituellement, les utilisateurs qui souhaitent savoir si la dernière mise à jour cumulative est installée sur leur système Windows 11/10 utilisent cette méthode pour vérifier l’historique des mises à jour Windows. Dans cet article, nous allons vous montrer comment obtenir des informations sur les correctifs actuels pour Windows 11/10 à l’aide d’un script PowerShell.

Script Powershell Pour Vérifier L'état De Windows Update

Script PowerShell pour vérifier l’état de Windows Update

Le script PowerShell peut être utilisé pour indiquer sur quelle version de système d’exploitation un ordinateur Windows 11/10 se trouve actuellement, ainsi que quelle mise à jour est la dernière mise à jour disponible pour l’appareil. Il peut également signaler toutes les mises à jour Windows publiées pour la version de Windows 11/10 sur laquelle se trouve actuellement un poste de travail.

Lorsque vous exécutez le script, les informations suivantes s’affichent :

  • Version actuelle du système d’exploitation
  • Édition actuelle du système d’exploitation
  • Numéro de version actuel du système d’exploitation
  • La mise à jour installée qui correspond à ce numéro de build, ainsi que le numéro KB et un lien vers la page d’informations
  • La dernière mise à jour disponible pour la version du système d’exploitation

Pour obtenir les informations sur les correctifs actuels de Windows 10 à l’aide du script PowerShell, vous devez créer et exécuter le script PowerShell à l’aide du code ci-dessous à partir de GithubGenericName.

Publicité
[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('','').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('','').Replace('—',' - '),
"KB" + $CurrentPatch.href.Split('/')[-1],
"https://support.microsoft.com" + $CurrentPatch.href,
$LatestAvailablePatch.outerHTML.Split('>')[1].Replace('','').Replace('—',' - '),
"KB" + $LatestAvailablePatch.href.Split('/')[-1],
"https://support.microsoft.com" + $LatestAvailablePatch.href
)
Return $Table

Vous pouvez exclure les mises à jour de prévisualisation ou hors bande disponibles qui sont plus récentes que celle que vous avez installée d’être signalées comme la dernière mise à jour disponible, vous pouvez donc vous concentrer uniquement sur les mises à jour cumulatives en exécutant la commande ci-dessous :

Get-CurrentPatchInfo -ExcludePreview -ExcludeOutofBand

Vous pouvez également répertorier toutes les mises à jour Windows publiées par Microsoft pour votre version de système d’exploitation avec la commande suivante :

Get-CurrentPatchInfo -ListAvailable

Si vous souhaitez exclure les mises à jour de prévisualisation et hors bande de la liste, mais répertorier toutes les mises à jour Windows que Microsoft a publiées pour votre version de système d’exploitation, exécutez la commande ci-dessous :

Get-CurrentPatchInfo -ListAvailable -ExcludePreview -ExcludeOutofBand

C’est ça!

Lire la suite: Le site PowerShell Module Browser vous permet de rechercher des applets de commande et des packages.

10 Using Powershell Script

Rate this post
Publicité
Article précédentL’entreprise de thé à bulles de Bristol qui a commencé dans une camionnette mobile célèbre son dixième anniversaire
Article suivantLes régulateurs de l’UE pourraient convaincre Google d’ouvrir YouTube Ad Business

LAISSER UN COMMENTAIRE

S'il vous plaît entrez votre commentaire!
S'il vous plaît entrez votre nom ici