Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connect to OU and Create User

Posted on 2006-11-16
3
Medium Priority
?
165 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 71

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 71

Accepted Solution

by:
Chris Dent earned 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

783 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