Link to home
Start Free TrialLog in
Avatar of alterniTECH
alterniTECH

asked on

How do I map network printers and drives using the Active Directory "Office" or ("physicalDeliveryOfficeName") field using vbs?

I would like to map network resources (such as printers and drives) based on the Active Directory Office field ("physicalDeliveryOfficeName") using .vbs as a logon script...   Can anyone assist with some basic script example?  I'm also considering using IP ranges or subnets...   Any assistance is GREATLY appreciated.  Thanks!
Avatar of tdukie13
tdukie13
Flag of United States of America image

Here is a .vbs I use for network printers...

Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\%SERVERNAME%\HP LaserJet"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
WScript.Echo "Check the Printers folder for : " & strUNCPrinter

WScript.Quit
Avatar of alterniTECH
alterniTECH

ASKER

Thanks, but what I'm trying to accomplish is this:
If user John Smith's Office contains "Atlanta" then map their printer to \\server1\printer1
The "Office" field in Active Directory is ("physicalDeliveryOfficeName")....
If your offices are set up as individual sites in Active Directory Sites and Services then it would be much easier to map the printers with GPOs linked at the site level.  That way the appropriate printers get mapped for any users who log onto computers at each site.

If you must use the office field, then here is an example of how to get its value for the current user.


On Error Resume Next
 
Set objSysInfo = CreateObject("ADSystemInfo")
 
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
 
strOffice = objUser.physicalDeliveryOfficeName
 
WScript.Echo strOffice

Open in new window

Hmm, interesting suggestion...  How does that work with AD?  Is it something like this?  A User logs into computer A that has an IP address of 192.168.2.99, site "MYSITE" covers the IP network of 192.168.2.x, so essentially I would only need to create a GPO that calls a logon.vbs from SysVol, associate that GPO to "MYSITE"...  Is there more to it, or just that simple?  AD is intelligent to know that the computer is IP 2.99 and it associates that computer with the site?  (Sorry for sounding dumb.....  But I am....  - OK, not dumb, just not that knowledgeable in this arena...)  Thanks for the help!
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, that was a great idea!!!  And although it didn't really give me an answer to what my question was, it provided me with a better solution to what I was getting at!  So thanks!