Uninstall Microsoft hotfixes with PowerShell

call function with:  Uninstall-HotFix -ComputerName PC1 -HotfixID KB123456

function Uninstall-Hotfix { [cmdletbinding()] param( $computername = $env:computername, [string] $HotfixID )

$hotfixes = Get-WmiObject -ComputerName $computername -Class Win32_QuickFixEngineering | select hotfixid

if($hotfixes -match $hotfixID) {     $hotfixID = $HotfixID.Replace(“KB”,””)     Write-host “Found the hotfix KB” + $HotfixID     Write-Host “Uninstalling the hotfix”     $UninstallString = “cmd.exe /c wusa.exe /uninstall /KB:$hotfixID /quiet /norestart”     ([WMICLASS]”\\$computername\ROOT\CIMV2:win32_process”).Create($UninstallString) | out-null

while (@(Get-Process wusa -computername $computername -ErrorAction SilentlyContinue).Count -ne 0) {         Start-Sleep 3         Write-Host “Waiting for update removal to finish …”     } write-host “Completed the uninstallation of $hotfixID” } else {

write-host “Given hotfix($hotfixID) not found” return }

}

from http://techibee.com/powershell/powershell-uninstall-windows-hotfixesupdates/1084

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s