Solved

Getting a users OU in a VB Script

Posted on 2007-04-09
3
1,964 Views
Last Modified: 2013-12-19
Howdy experts.  I was wondering if someone could tell me how to determine the OU a user is in a VB Script.  I was doing something like this for the group:

      Const ENGINEERING_GROUP     = "cn=engineering"

      Set wshNetwork = CreateObject("WScript.Network")
      wshNetwork.MapNetworkDrive "h:", "\\FileServer\Users\" & wshNetwork.UserName
      Set ADSysInfo = CreateObject("ADSystemInfo")
      Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
      strGroups = LCase(Join(CurrentUser.MemberOf))

      If InStr(strGroups, ENGINEERING_GROUP) Then
          wshNetwork.MapNetworkDrive "g:",
          "\\FileServer\Engineering\"

I was hoping that I could change the Const declaration to something like
      Const ENGINEERING_GROUP     = "ou=engineering"

but I am not sure how to modify the following two lines:
      Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
      strGroups = LCase(Join(CurrentUser.MemberOf))

all of  your help is appreciated in advance...a
0
Comment
Question by:Atropa
[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
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18878740
Not sure what you mean...
This should be all you need to get at the OU:

Set ADSysInfo = CreateObject("ADSystemInfo")
strUser=AdSysInfo.UserName
strOU=Mid(strUser,instr(strUser,"OU"),instr(mid(strUser,instr(strUser,"OU")),",")-1)
msgbox strOU
0
 
LVL 5

Author Comment

by:Atropa
ID: 18878761
I'll try it, thnx
0
 
LVL 5

Author Comment

by:Atropa
ID: 19019966
Here is what I did.  It was basically from your response and it seems to work:

Const TORRANCE_1      = "ou=torrance_1"
Const TORRANCE_2      = "ou=torrance_2"
Const SAN_BERNARDINO      = "ou=san_bernardino"

' Scripting Constants
Const sNet            = "WScript.Network"
Const xNet            = "ADSystemInfo"

Set wNet             = CreateObject(sNet)
Set ADSI             = CreateObject(xNet)
Set cUsr            = GetObject("LDAP://" & ADSI.UserName)

sOU = LCase(Join(cUsr.MemberOf))

' Check OU name and map the K Drve to the appropriate server/share
      With wNet
            If InStr(sOU, TORRANCE_1) Then
                  .MapNetworkDrive "K:", "\\cls3\develope6\"
'                  .AddWindowsPrinterConnection "\\PrintServer\EngLaser"
'                  .SetDefaultPrinter "\\PrintServer\EngLaser"
            ElseIf InStr(sOU, TORRANCE_2) Then
                  .MapNetworkDrive "K:", "\\nbserver\developer6\"
            End If
      End With
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

SHARE your personal details only on a NEED to basis. Take CHARGE and SECURE your IDENTITY. How do I then PROTECT myself and stay in charge of my own Personal details (and) - MY own WAY...
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

627 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