Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting a users OU in a VB Script

Posted on 2007-04-09
3
Medium Priority
?
1,973 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 1500 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

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

Question has a verified solution.

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

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…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

670 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