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
674 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:alterniTECH
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now