Jason Yu
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
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]"\\$computernam e\ROOT\CIM V2:win32_p rocess").C reate($Uni nstallStri ng) | 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_needremo ve.txt"
foreach ($computer in $myComputers) {
Uninstall-HotFix -ComputerName $computer -HotfixID KB3097877
}
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
}
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]"\\$computernam
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_needremo
foreach ($computer in $myComputers) {
Uninstall-HotFix -ComputerName $computer -HotfixID KB3097877
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
I checked in "OPTIONS || SYNCHRONIZATION SCHEDULE" and found out that we have schedule to synchronize daily at 10:20 PM.
ASKER
So, after I download and approve the new revised patch, it will replace the old installed patch on all workstations?
Please advise, thanks.
Please advise, thanks.
Yes it will
ASKER
Thanks, I will do it.
Uninstall-HotFix -ComputerName $myComputers -HotfixID kb3097877