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
Solved

Getting a users OU in a VB Script

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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

Recently, I read that Microsoft has analysed statistics for their security intelligence report. It revealed: still, the clear majority of windows users do their daily work as administrator. An administrative account is a burden, security-wise. My ar…
Resolve DNS query failed errors for Exchange
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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