Link to home
Start Free TrialLog in
Avatar of Jason Yu
Jason YuFlag for United States of America

asked on

A script to remove a specific installed patch in a domain.

I have approved a patch with some conflict ions with Office 2010 modules, the KB number is 3097877. I have researched online and combined a script like below. However, when I ran this script with a complied computer name list file, it gave me errors like below. Please help me modify this script to make it possible.

Thanks.

Script
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
}            

}



$myComputers = Get-Content "c:\PowerShell Scripts\computers_needremove.txt"
foreach ($computer in $myComputers) {
 Uninstall-HotFix -ComputerName $computer -HotfixID KB3097877
}

Open in new window



Error i got when running the above script:


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
}            

}



$myComputers = Get-Content "c:\PowerShell Scripts\computers_needremove.txt"
foreach ($computer in $myComputers) {
 Uninstall-HotFix -ComputerName $computer -HotfixID KB3097877
}
Avatar of FOX
FOX
Flag of United States of America image

The line Uninstall-Hotfix should read

Uninstall-HotFix -ComputerName $myComputers -HotfixID kb3097877
ASKER CERTIFIED SOLUTION
Avatar of FOX
FOX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jason Yu

ASKER

We use WSUS server to deploy windows patches, how could I redownload the same patch on WSUS server?

I couldn't find a place to delete the old version, please help.
in wsus do a download of new updates and it will pull down the fixed kb that was corrupted last week.  It is using the same kbnumber How often does your wsus server pull down updates?  It may have pulled it down already.
I checked in "OPTIONS || SYNCHRONIZATION SCHEDULE" and found out that we have schedule to synchronize daily at 10:20 PM.
So, after I download and approve the new revised patch, it will replace the old installed patch on all workstations?

Please advise, thanks.
Yes it will
Thanks, I will do it.