Solved

Find OU Path of Users and Export to LDAP

Posted on 2009-06-29
1
865 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
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

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

13 Experts available now in Live!

Get 1:1 Help Now