Solved

Connect to OU and Create User

Posted on 2006-11-16
3
155 Views
Last Modified: 2010-04-30
I need a script that will determine the domain, connect to an ou (strOU) then Create a user. Please post your script and help here
0
Comment
Question by:dion_p1
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17954438

Lots of questions ;)


Set objRootDSE = GetObject("LDAP://RootDSE")
Set objOU = GetObject("LDAP://OU=SomeOU," & objRootDSE.Get("defaultNamingContext"))

objOU.Create("user", "CN=User Name")

After that you can set user properties as you see fit followed by "objUser.SetInfo".

Chris
0
 

Author Comment

by:dion_p1
ID: 17954497
Will this work if the OU is three or four OU's deep?
Also How do i set the strDomain String for userPrincipalName if im trying to Determine the Domain.

strOU = "ounamehere"
strUserID = "usernamehere"

Set objRootDSE = GetObject("LDAP://RootDSE")
Set objOU = GetObject("LDAP://" & strOU & ," & objRootDSE.Get("defaultNamingContext"))

Set objUser = objOU.Create("user", "CN=" & strUserID)
    objUser.Put "samAccountName", strUserID
    objUser.Put "userPrincipalName", strUserID & strDomain
    objUser.Put "sn", strSurname
    objUser.Put "givenName", strFirstName
    objUser.Put "displayName", strFirstname & " " & strSurname
    objuser.Put "description", "Student User - " & strGroup
    objUser.SetInfo
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 17954556

Nope, you would need to provide the full path to the OU - this is unavoidable if you want the nice quick way to create the user. If you're to search for the OU then you really only have two options: ADODB (an SQL type query using ADO) or Recursion.

Anyway, I'll describe both of these in your other thread so hopefully it will become clear from that.

Chris
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 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

26 Experts available now in Live!

Get 1:1 Help Now