Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

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!
0
alterniTECH
Asked:
alterniTECH
  • 3
  • 2
1 Solution
 
tdukie13Commented:
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
0
 
alterniTECHAuthor Commented:
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")....
0
 
Shift-3Commented:
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

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

 
alterniTECHAuthor Commented:
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!
0
 
Shift-3Commented:
That is essentially it.  AD knows which site a computer is in based on its subnet, as assigned in AD Sites and Services.  When a GPO is linked to a site, settings in the Computer Configuration node apply to all computers in the site and settings in the User Configuration node apply to all users who log onto those computers.  You don't have to turn on loopback processing.

So, create separate GPOs linked to each site and configure a script in each GPO under the node User Configuration\Windows Settings\Scripts\Logon.  Put the scripts in the default directories which the GPOs create.  These will automatically get replicated to all DCs, so you don't have to worry about that.

The big advantage of this method is that once it's set up you have very little to maintain.  When a user logs onto a computer, they get the drives and printers for that site.  If they travel to another office and either plug in their laptop or log onto one of the workstations, they get the new site's drives and printers.
0
 
alterniTECHAuthor Commented:
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!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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