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

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.
0
greenbeanx81
Asked:
greenbeanx81
  • 7
  • 4
1 Solution
 
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
 
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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
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

Featured Post

Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

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