?
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
Medium Priority
?
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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

 

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 2000 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 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