Solved

Getting a users OU in a VB Script

Posted on 2007-04-09
3
1,949 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
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
OfficeMate Freezes on login or does not load after login credentials are input.
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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