Directory Services

Deleting an ADAM Organizational Unit

[This documentation is preliminary and subject to change.]

To delete an organizational unit (OU), bind to the object that contains the OU and delete the organizationalUnit object.

You can create the object you delete with the following code example by Creating an ADAM Organizational Unit.

The following VBScript code example uses the GetObject function to bind to an organization object and uses the Delete method to delete a selected organizationalUnit object in that organization.

' Delete ADAM Organizational Unit.

Option Explicit

Dim objADAM  ' Binding object.
Dim strOU	' OU to delete.
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"

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 "Delete:  OU=" & strOU

' Delete OU.
objADAM.Delete "organizationalUnit", "OU=" & strOU

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