Scipt to Delete all printers on a specific print server

We have built out a completely new print server and are mapping the printers using GPP. We would like to delete all printers that are mapped to our old print server only. Apparently the printer section of GPP does not allow for wildcards so delete \\server\* does not work. We also do not want to just delete all UNC printers. Im looking for a VB script (or somthing similar) that will delete all printers mapped to \\Server1.
irishpaulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

merowingerCommented:
check out the script below.I just cannot test it, as i have no printers mapped :)
Set objNetwork = CreateObject("WScript.Network") 
strServername = "ServerX"

Set objPrinter = objNetwork.EnumPrinterConnections

For intDrive = 0 To (objPrinter.Count -1) Step 2
	If Instr(objPrinter.Item(intDrive),strServername) Then
		objNetwork.RemovePrinterConnection objPrinter.Item(intDrive)
	End If
Next

Open in new window

irishpaulAuthor Commented:
So i just change "ServerX" to my server name without any slashes and this will delete any network printer that points to "ServerX". Testing will accept upon success.
merowingerCommented:
Yes replace the servername without slashes.
As i said i could not test it. This is your part :)
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

irishpaulAuthor Commented:
modifying that script with my server in place of 'ServerX' does not delete any printers. Im local admin on my box. Just copied and pasted to notepad and saved as .vbs No errors or popups.
merowingerCommented:
ok could you post the result of the following:


Set objNetwork = CreateObject("WScript.Network")
strServername = "ServerX"

Set objPrinters = objNetwork.EnumPrinterConnections

For i=0 to objPrinters.count-1
        wscript.echo objPrinters.Item(i)
        If Instr(objPrinters.Item(i),strServername) Then
            Wscript.echo "delete - " &objPrinters.Item(i)
            'objNetwork.RemovePrinterConnection objPrinters.Item(i)
        End If
Next
irishpaulAuthor Commented:
Shows all printers installed on my machine. Local, Shared, everything.
merowingerCommented:
is there also the "delete" line included? Have you customized the servername?
irishpaulAuthor Commented:
uploaded GIF showing result.
VBS.gif
merowingerCommented:
is the delete result correct? Iy es then remove the ' character from this line:
'objNetwork.RemovePrinterConnection objPrinters.Item(i)

and check if the printers are deleted
irishpaulAuthor Commented:
Im not sure what you mean by "is the delete result correct?" If you are asking if i want the script to delete all the printers that are shown in that image then the answer is no. I am trying to delete all printers that are mapped to \\PV-SRV-0022. All the rest should remain mapped to my machine.
merowingerCommented:
so the script has found the correct entries which shell be deleted (see picture)

Just execute it to see if the printers are removed
Set objNetwork = CreateObject("WScript.Network") 
strServername = "PV-SRV-0022"

Set objPrinters = objNetwork.EnumPrinterConnections

For i=0 to objPrinters.count-1 
        If Instr(objPrinters.Item(i),strServername) Then
            objNetwork.RemovePrinterConnection objPrinters.Item(i)
        End If 
Next

Open in new window

VBS.gif
irishpaulAuthor Commented:
The last script you posted does not work. I modified the previous script you sent "04/14/10 12:26 PM, ID: 30750708" and removed the comma that worked like a charm. Can you repost that script without the comma and ill accept as solution.
merowingerCommented:
strange :)
Set objNetwork = CreateObject("WScript.Network") 
strServername = "ServerX"

Set objPrinters = objNetwork.EnumPrinterConnections

For i=0 to objPrinters.count-1 
        wscript.echo objPrinters.Item(i)
        If Instr(objPrinters.Item(i),strServername) Then
            Wscript.echo "delete - " &objPrinters.Item(i)
            objNetwork.RemovePrinterConnection objPrinters.Item(i)
        End If 
Next

Open in new window

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
merowingerCommented:
is it working now?
Brent387Commented:
I haven't tried this since I don't want to delete the printers on our server. Lemme know how it goes.

Set WS_NET = CreateObject("wscript.network")
            Set WS_PRINTERS = WS_NET.EnumPrinterConnections
            For LOOP_COUNTER = 0 To WS_PRINTERS.Count - 1 Step 2
                MsgBox WS_PRINTERS(LOOP_COUNTER) & vbTab & WS_PRINTERS(LOOP_COUNTER + 1)
                'WS_NET.removeprinterconnection WS_PRINTERS(LOOP_COUNTER + 1)
                'WS_NET.removeprinterconnection WS_PRINTERS(LOOP_COUNTER)
            Next
            Set WS_PRINTERS = Nothing
            Set WS_NET = Nothing

Open in new window

Brent387Commented:
Btw, I found that from another expert comment: aelatik
So if that works, give him some credit please.
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
VB Script

From novice to tech pro — start learning today.