Need something adding to VBScript for Adding and Deleting Printers

Basically i have some code for a VBScript which adds printers to a clients PC that refers to the print server at the location.

We have an old print server (ICHOLS22) which is being replaced by the new one (GBHOLFP01)

Here is the script i have so far:

On Error Resume Next

Dim net
Dim NetPrinter
Dim Printer


Set net = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
        Printer = UCase(
        If Printer <> "\\GBHOLFP01\PRN1918036" then
            net.RemovePrinterConnection printer
        end If

net.AddWindowsPrinterConnection "\\GBHOLFP01\PRN1918036"
net.AddWindowsPrinterConnection "\\GBHOLFP01\PRN5500380"
net.SetDefaultPrinter "\\GBHOLFP01\PRN5500380"

What i need to add to this is a removal of any printer from the clients PC that refers to the old ICHOLS22 printer.

Can anyone help?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

You already have it set to Remove any Printer Connection not called "\\GBHOLFP01\PRN1918036". If that's not working then remove the line that says "On Error Resume Next" and re-run the script.


PhilJMcDougallAuthor Commented:
Yes that works already the bit where i have said don't remove the selected printer, problem is they have other printers on there (random ones that i can't add into the script) from other print servers so i just want to remove printers that recide on ICHOLS22.

net.RemovePrinterConnection "\\ICHOLS22\PRN00500000"
                                           ^ this part to remove
add this for the printers you wish to remove.

If Printer <> "\\GBHOLFP01\PRN1918036" then
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000001"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000002"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000003"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000004"
end If

quick fix

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PhilJMcDougallAuthor Commented:
Worked a treat. cheers Zell71!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.