Solved

Connect to OU and Create User

Posted on 2006-11-16
3
157 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 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

25 Experts available now in Live!

Get 1:1 Help Now