Solved

Connect to OU and Create User

Posted on 2006-11-16
3
162 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
[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
  • 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

738 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