?
Solved

Remove KB with script - problem running script

Posted on 2016-08-05
2
Medium Priority
?
135 Views
Last Modified: 2016-08-09
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
}
0
Comment
Question by:hernandez5999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 2000 total points
ID: 41744511
What error is it giving you?
What did you name the file?
How are you trying to run it?

This is a POWERSHELL script, not a Visual Basic Script.
The file should be saved as a .PS1 file
0
 
LVL 3

Author Closing Comment

by:hernandez5999
ID: 41749287
Changed it to .ps1 and ran it with no problem.
thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question