?
Solved

Find OU Path of Users and Export to LDAP

Posted on 2009-06-29
1
Medium Priority
?
910 Views
Last Modified: 2012-05-07
I am currently migrating users to a new SAN and am writing a script to automate most of the process. What I am running into is having to change the LDAP string to suit the user I am migrating (specifically OU's). Does anyone know of a way to search for an AD user and output the OU path to a LDAP string? We have a pretty deep OU "tree", so it would look something like this:

Domain.com
---Staff
-------IT
-----------Test Accounts
-------Business
---Guests
-------so on and so forth

I'm using vb script to code this and any help or push in the right direction would help out tremendously.

Thanks.
0
Comment
Question by:b4sherx
[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
1 Comment
 
LVL 1

Accepted Solution

by:
b4sherx earned 0 total points
ID: 24737704
Found a good resource here, but had to modify it to suit my needs:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1021.mspx

Here's what I ended up doing:

On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
 
FindUser = InputBox("Please Enter A UserName", "Find User OU")
If FindUser = "" Then
MsgBox("No UserName Was Added")
WScript.Quit
Else
strUser = FindUser
End If
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
objCommand.CommandText = _
    "SELECT distinguishedName FROM 'LDAP://dc=leeflames,dc=lan'WHERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
Set objRecordSet = objCommand.Execute
 
objRecordSet.MoveFirst
strDN = objRecordSet.Fields("distinguishedName").Value
 
'Removed all the parsing and the loop
'    arrPath = Split(strDN, ",")
'    intLength = Len(arrPath(1))
'    'intNameLength = intLength - 3
'    Wscript.Echo Right(arrPath(1), intLength)
 
'Echoed out the full string for debugging    
Wscript.Echo strDN
 
Set objUser = GetObject("LDAP://" & strDN)

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

762 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