The All-Purpose ADSI Object Deletion Script
This template script looks a lot like the object creation script to start with.
strContainer = ""
strName = "UserName"
'generic part
Set objRootDSE = GetObject("LDAP://rootDSE")
If strContainer = "" Then
Set objContainer = GetObject("LDAP://" & _
objRootDSE.Get("defaultNamingContext"))
Else
Set objContainer = GetObject("LDAP://" & _
strContainer & "," & _
objRootDSE.Get("defaultNamingContext"))
End If
This code simply connects to a container, such as an OU. After you're connected, you can delete the object, such as a user.
objContainer.Delete "user", "cn=" & strName
You can reuse this line of code to delete a contact, computer, or group just by replacing "user" with "contact", "computer", or "group" as appropriate. Nothing could be simpler.
|