Create Add / Remove Printer script based on User or Computer location?

Hello Everyone,

I am currently implementing roaming profiles at a company. One of the tasks I do is assign / remove printers based on where the user or computer resides. The company has a main branch at 172.21.173.x/24 with a domain controller acting as file / share print server. The branch at 172.21.174.x/24 has a second domain controller acting also as a print server with XOsoft replicating files to it one way. My question is what would be the best way to accomplish this. I am not familiar with scripting to much for this task so I need help with examples. Their are users that reside at each branch that travel to the other branch so I would need the script to clear the printers and remap based on profile. As far as I know this can be done through subnet, site, OU membership, or Group Membership. OU and Group membership probably would be the best idea because each shares a certain number of users. Could it be done through subnet or site membership? How about printers tied to a computer using GPO? Thank you.
greenbeanx81Asked:
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.

m203hconCommented:
we use a vm script
Option Explicit

DIM RegEntry, ComputerName



RegEntry="HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"

ComputerName = ReadRegValue(RegEntry)

if InStr(1,ucase(ComputerName),"COMPUTER1",vbTextCompare) > 0 then call SetPrinter("Lexmark T520")



if InStr(1,ucase(ComputerName),"COMPUTER2",vbTextCompare) > 0 then call SetPrinter("Canon LBP-1760")

if InStr(1,ucase(ComputerName),"COMPUTER3",vbTextCompare) > 0 then call SetPrinter("Lexmark E320")
wscript.quit



' ***  This subroutine installs and sets the default printer

Sub SetPrinter(ByVal PrinterPath)

  DIM WshNetwork

  Set WshNetwork = CreateObject("WScript.Network")

' ***   WshNetwork.AddWindowsPrinterConnection(PrinterPath)

  WshNetwork.SetDefaultPrinter Printerpath

end sub



' ****  This function returns the data in the registry value

Function ReadRegValue(ByVal RegValue)      

  DIM WSHShell

  Set WSHShell = WScript.CreateObject("WScript.Shell")

  ReadRegValue=""

  On Error Resume Next

  ReadRegValue= WSHShell.RegRead(RegValue)

End Function
0

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
greenbeanx81Author Commented:
I'm looking at your script and I'm trying to figure out whats going on. The printers in question are network printers. I assume you are using in registry to set the printers if the computer matches and setting the defaults. If the computers do not the match the script exits. Would I add a second script to map a printers to other set of computers. I have 25 pcs in one location and 7 at the branch. Would this be feasible to use? I would place these as a start up script on the computer configuration as a vbs or bat file? Thanks

0
m203hconCommented:
if you want a shared printer use
if InStr(1,ucase(ComputerName),"COMPUTER1",vbTextCompare) > 0 then call SetPrinter("\\server\printersharename")
you can set it up 2 manners
i put it in the logon script on the server
i have a network from 160 computers they are all in the script (i do it when i place a new computer) if i replace a computer a do a find and replace it's 30 seconds work
or you can run it in the startup of the computer who needs to change his printer
it is than local on the computer
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

greenbeanx81Author Commented:
Ok so I can set this scrip to run and set printers by computer name..excellent. Do I save this as *.vbs or *.bat? Question is. what line determines what printer is set by default if I have two or three printers loaded on the computer?
0
m203hconCommented:
putty command line http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter3.html#using-cmdline
putty.exe [-ssh | -telnet | -rlogin | -raw] [user@]host
putty.exe -load "session name"
-m: read a remote command or script from a file
0
m203hconCommented:
oh sorry wrong answer on wrong tab
i named it printer.vbs
0
greenbeanx81Author Commented:
lol...thanks..
0
greenbeanx81Author Commented:
Just wondering..any good books on learning AD scripting and automation..seems very powerful an can save me the headache of managing users and computers
0
greenbeanx81Author Commented:
I tried your script and it only sets the default printer. Is their a way to install / map network printers for a user and set the defaults based on computer locations. Thanks.
0
greenbeanx81Author Commented:
Never mind..I didn't comment out the install field. Thanks.
0
greenbeanx81Author Commented:
Any good books on learning scripting?
0
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
Active Directory

From novice to tech pro — start learning today.