16th June 2016
How to uninstall KB-article with powershell remotely
If you get an update that you what to uninstall the best way is to use powershell.
This function uninstalls the kb-article you ask for if it is installed on the system.
To use it you have to run it as administrator.
uninstall-hotfix -computername “replace with name” -hotfixID “Replace with numbers only”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
function Uninstall-Hotfix { [cmdletbinding()] param( $computername = $env:computername, [string] $HotfixID ) $hotfixes = Get-WmiObject -ComputerName $computername -Class Win32_QuickFixEngineering | Select-Object -Property hotfixid if($hotfixes -match $HotfixID) { $HotfixID = $HotfixID.Replace('KB','') Write-Host 'Found the hotfix KB' + $HotfixID Write-Host -Object 'Uninstalling the hotfix' $UninstallString = "cmd.exe /c wusa.exe /uninstall /KB:$HotfixID /quiet /norestart" $null = ([WMICLASS]"\\$computername\ROOT\CIMV2:win32_process").Create($UninstallString) while (@(Get-Process -Name wusa -ComputerName $computername -ErrorAction SilentlyContinue).Count -ne 0) { Start-Sleep -Seconds 3 Write-Host -Object 'Waiting for update removal to finish ...' } Write-Host -Object "Completed the uninstallation of $HotfixID" } else { Write-Host -Object "Given hotfix($HotfixID) not found" -ForegroundColor white -BackgroundColor red return } } |