The function Remove-KBPackage
that we are going to create will search and uninstall Windows Update packages based on the provided KB (Knowledge Base) number.
function Remove-Package {
param(
[string]$KB
)
# Recherche du ou des packages
$packages = Get-WindowsPackage -Online | Where-Object { $_.PackageName -match $KB }
if($packages.Count -eq 0) {
Write-Host "No packages found matching $KB."
return
}
# Affichage des packages trouvés
Write-Host "Packages found matching $KB"
$packages | ForEach-Object { Write-Host $_.PackageName }
# Suppression des packages
foreach($package in $packages) {
try {
Write-Host "Uninstalling $($package.PackageName)..."
Remove-WindowsPackage -Online -PackageName $package.PackageName -NoRestart -ErrorAction Stop
Write-Host "$($package.PackageName) uninstalled successfully."
} catch {
Write-Error "Failed to uninstall $($package.PackageName). Error: $_"
}
}
Write-Host "Please restart your computer."
}
# Exemple d'utilisation
Remove-Package -KB "KB4589210"
If you want to uninstall a Cumulative Update, first identify the Windows version.
For example, to uninstall the update from November 14, 2023, Use Remove-Package -KB “KB17763.5122”
0 Comments