Solved

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

Posted on 2009-07-07
6
681 Views
Last Modified: 2012-05-07
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
Comment
Question by:alterniTECH
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:tdukie13
ID: 24797791
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
 

Author Comment

by:alterniTECH
ID: 24797875
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
 
LVL 38

Expert Comment

by:Shift-3
ID: 24798328
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:alterniTECH
ID: 24798958
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
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 24799471
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
 

Author Closing Comment

by:alterniTECH
ID: 31606812
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question