Link to home
Start Free TrialLog in
Avatar of Jose Rivera-Hernandez
Jose Rivera-HernandezFlag for United States of America

asked on

Remove KB with script - problem running script

I am running this script that I found here, but it is giving me this error. The script is vbs, should it be different? I am trying to run it in a Terminal server 2012 to remove a KB in multiple computers.



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","3172605")
    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:\Users\jrhernandez\Desktop\computers.txt"
foreach ($computer in $myComputers) {
 Uninstall-HotFix -ComputerName $myComputers -HotfixID KB3172605
}
ASKER CERTIFIED SOLUTION
Avatar of Darrell Porter
Darrell Porter
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 Jose Rivera-Hernandez

ASKER

Changed it to .ps1 and ran it with no problem.
thanks!