Directory Services

Creating an ADAM Organizational Unit

[This documentation is preliminary and subject to change.]

To create an organizational unit, bind to the object that will contain the organizational unit, create an organizationalUnit 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 Organizational Unit.

The following VBScript code example uses the GetObject function to bind to an organization object and uses the Create method to create an organizationalUnit object in that organization.

' Create ADAM Organizational Unit.

Option Explicit

Dim objADAM		 ' Binding object.
Dim objOU		 ' Organizational unit.
Dim strDescription  ' Description of OU.
Dim strOU		 ' Organizational unit.
Dim strPath		 ' Binding path.

' 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 Organizational Unit.
strOU = "TestOU"
strDescription = "ADAM Test Organizational Unit"

On Error Resume Next

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

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

WScript.Echo "Create:  OU=" & strOU

' Create an organizational unit.
Set objOU = objADAM.Create("organizationalUnit", "OU=" & strOU)
objOU.Put "description", strDescription

' Output success or error.
If Err.Number <> vbEmpty Then
	WScript.Echo "Error: Create failed."
	WScript.Echo "Success: Organizational Unit created."
End If