Directory Services

Creating an ADAM User

[This documentation is preliminary and subject to change.]

To create an ADAM user, bind to the object that will contain the user, create a user object, set its properties, and save the object to the directory store.

You can delete the object you create with the following code example by Deleting an ADAM User.

The following VBScript code example uses the GetObject function to bind to an organization object, uses the Create method to create a user object in that organization, and sets some properties of the user.

' Create ADAM User.

Option Explicit

Dim objADAM			 ' Binding object.
Dim objUser			 ' User object.
Dim strDisplayName		' Display name of user.
Dim strPath			 ' Binding path.
Dim strUser			 ' User to create.
Dim strUserPrincipalName  ' Principal name of user.

' Construct ADAMsPath binding string.
' Change "localhost" to appropriate server.
' Change "389" to port for appropriate instance.
' Change "O=Fabrikam,C=US" to appropriate object.
strPath = "LDAP://localhost:389/O=Fabrikam,C=US"

WScript.Echo "Bind to: " & strPath

' Specify User.
strUser = "TestUser"
strDisplayName = "Test User"
strUserPrincipalName = "TestUser@Fabrikam.Us"

WScript.Echo "Create:  " & strUser
WScript.Echo "		 " & strDisplayName
WScript.Echo "		 " & strUserPrincipalName

On Error Resume Next

' Bind to object.
Set objADAM = GetObject(strPath)

' Output error if bind fails.
If Err.Number <> vbEmpty Then
	WScript.Echo "Error:   Bind failed."
	WScript.Quit
End If

' Create User.
Set objUser = objADAM.Create("user", "CN=" & strUser)
objUser.Put "displayName", strDisplayName
objUser.Put "userPrincipalName", strUserPrincipalName
objUser.SetInfo

' Output success or error.
If Err.Number <> vbEmpty Then
	WScript.Echo "Error:   Create failed."
Else
	WScript.Echo "Success:   User created."
	WScript.Echo "UserName:  " & objUser.user
	WScript.Echo "Display:   " & objUser.displayName
	WScript.Echo "Principal: " & objUser.userPrincipalName
End If