• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Delete Particular Mapped Network Printers with Scripts.

Hi,

May be this would be sort of repeated question. But i cannot find the exact solution for my problem.

To say, we are migrating from an Old Print Server (Win2K) to a New Print Server (Win2K3 R2). All clients are Win2K. Clients have different printers mapped as per their location in different buildings. I need to create a script that would allow me to delete only those printers which i mention, NOT ALL. I have script to map the network printers i want and works fine. I also got one Script as below that helps me to delete only one network printer.
#####################
Option Explicit
Dim DelPrint, UNCpath
UNCpath = "\\Server1\Printer"
Set DelPrint = WScript.CreateObject("WScript.Network")
DelPrint.RemovePrinterConnection UNCpath, true, true
Wscript.Echo "This printer was removed : " & UNCpath
WScript.Quit

' End of Example Script to remove printer
#######################

This only allows me to enter ONE uncpath.
- I want a script that will allow me to mention all the network printers to be deleted in a single script.
- If the printers mentioned in the script are not present, it will ignore, else shall delete that printer. No error messages if any printer mentioned in the script is not found on the Client PC.

I hope i am clear and request to please guide me.

Thanks,

Suhail.
0
suhailkardekar
Asked:
suhailkardekar
1 Solution
 
Shift-3Commented:
Option Explicit
Dim arrDelPrint, objNetwork, objWMIService, colPrinters, objPrinter, strPrinter

'Add the UNC paths of all printers to remove here
arrDelPrint = Array("\\server1\printer1","\\server1\printer2","\\server2\printer1")

Set objNetwork = CreateObject("Wscript.Network")

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
For Each objPrinter in colPrinters
   'Checks that the network printer exists before unmapping it.
   If Not objPrinter.Attributes And 64 Then
      For Each strPrinter in arrDelPrint
         If LCase(strPrinter) = LCase(objPrinter.ServerName & "\" & objPrinter.ShareName) Then
            objNetwork.RemovePrinterConnection strPrinter
         End If
      Next
   End If
Next
0
 
suhailkardekarAuthor Commented:
Hi,

Thats exactly what i needed.

Thanks a thousandfold.

Suhail.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now