compdigit44
asked on
Script to Delete Old Mappings to Print Server with Share Name Like
OK here if my problem and it is one that I got myself into.... I am in the process of migrating our Windows 2008 printer cluster to 2008 R2 which host 600+ printers. All printers are deployed via GPP. So I updated each existing GPP for each printer to point to the new cluster and everything worked perfectly. I thought that it would change the current mapping to the new printer server. What it did is that is created another instance of the printer on the new cluster so now user's have duplicate mappings...
I know what you are thinking testing?? Well this is one item I over looked .
I know GPP can remove a printer but it needs the full UNC path name... I can do this for 600+ printer but this not very efficient.
Online I found a script someone wrote that deletes all printers that are connected to a printer serve which is great but I need to remove printer mappings in a more controlled fashions since some printers were removed.
I need a script that will delete all printers on a server with a share name that starts with .. Here's an example...
\\server\HP 43 or \\server\Room 123 H or \\server\123
All clients are Windows 7 I am not a scripting person so I turn to the experts for help
I know what you are thinking testing?? Well this is one item I over looked .
I know GPP can remove a printer but it needs the full UNC path name... I can do this for 600+ printer but this not very efficient.
Online I found a script someone wrote that deletes all printers that are connected to a printer serve which is great but I need to remove printer mappings in a more controlled fashions since some printers were removed.
I need a script that will delete all printers on a server with a share name that starts with .. Here's an example...
\\server\HP 43 or \\server\Room 123 H or \\server\123
All clients are Windows 7 I am not a scripting person so I turn to the experts for help
Hello compdigit44 - you could but I'm thinking more of a basic dos batch file that will do the same, this would probably be easier/simpler.
Something like this:
Can you try the above command on a cmd prompt? It should echo the connected \\server\printers - if it works, remove the echo (after the @). If you want to put it into a batch file, all %a must be %%a
Something like this:
for /f "tokens=3 delims= " %a in ('net use ^| findstr /i \\\\server') do @echo net use "%a" /d
Can you try the above command on a cmd prompt? It should echo the connected \\server\printers - if it works, remove the echo (after the @). If you want to put it into a batch file, all %a must be %%a
also try this vbs version that may be easier to include in logon script
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
dim srvName
srvName = "\\SUSIE-PC\"
WScript.Echo
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
if left(oPrinters.Item(i+1),len(srvName))=srvName then
WScript.Echo "Delete#" & i & "=Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
'objNetwork.RemovePrinterConnection oPrinters.Item(i+1)
end if
Next
ASKER
Everyone thanks for the help. I will be trying this first thing tomorrow morning. DO either script delete a printer is the share name starts with something. Also can the script handle spaces in the share name
net use will not handle your printers with a space in the name properly (why do people do that btw).
Can you show the output this reg query:
reg query HKCU\printers
Can you show the output this reg query:
reg query HKCU\printers
ASKER
The printers where name this way long before I state at my company 6 months ago....
A sample of HKCU\printers looks like the following
\\ServerA\HP LaserJet 4350 RM33 PCL6
\\ServerA\Ricoh 443
A sample of HKCU\printers looks like the following
\\ServerA\HP LaserJet 4350 RM33 PCL6
\\ServerA\Ricoh 443
Ok, try this then instead:
for /f "tokens=* delims= " %%a in ('reg query HKCU\printers ^| findstr /i \\\\servera') do echo net use "%%a" /d
Using at test file containing your sample HKCU\printers I got this from a command line test:
for /f "tokens=* delims= " %%a in ('reg query HKCU\printers ^| findstr /i \\\\servera') do echo net use "%%a" /d
Using at test file containing your sample HKCU\printers I got this from a command line test:
C:\Temp>for /f "tokens=* delims= " %a in ('type test.txt ^| findstr /i \\\\servera') do echo net use "%a" /d
C:\Temp>echo net use "\\ServerA\HP LaserJet 4350 RM33 PCL6" /d
net use "\\ServerA\HP LaserJet 4350 RM33 PCL6" /d
C:\Temp>echo net use "\\ServerA\Ricoh 443 " /d
net use "\\ServerA\Ricoh 443 " /d
ASKER
Thanks but the problem is that I have 20 or 30 types of printers on my network
ASKER
From the link I posted earlier would it work if I took the line and did the following....
PrintServer = "SERVERNAME" 'Your Print server name goes here
PrintServer = "\\ServerA\HP 43*" (* means anthing following.
From what I have read about win32_print I would need to us / call ServerName and ShareName
Please Help!!!!!! :o(
PrintServer = "SERVERNAME" 'Your Print server name goes here
PrintServer = "\\ServerA\HP 43*" (* means anthing following.
From what I have read about win32_print I would need to us / call ServerName and ShareName
Please Help!!!!!! :o(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
note!!! i removed the comment mark from the RemovePrinter line 11 above,
Add it back for your testing.
Add it back for your testing.
ASKER
SO far this is working perfectly!!!!
I am doing a couple more test thought just to be sure
I am doing a couple more test thought just to be sure
ASKER
http://community.spiceworks.com/scripts/show/632-remove-all-network-printers-by-print-server-name