Solved

Getting a users OU in a VB Script

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

19 Experts available now in Live!

Get 1:1 Help Now