Open ADSI Edit.
If an entry for the naming context you want to browse is not already displayed, do the following:
In the left pane, browse to the object you want to delete.
Right-click on the object and select Delete.
Click Yes to confirm.
This recipe covers deleting individual objects. If you want to delete a container or OU and all the objects in it, take a look at Recipe 4.21.
If the parent container of the object you want to delete has a lot of objects in it, you may want to add a new connection entry for the DN of the object you want to delete. This may save you time searching through the list of objects in the container and could help avoid accidental deletions. You can do this by right-clicking ADSI Edit and selecting Connect to. Under Connection Point, select Distinguished Name and enter the DN of the object you want to delete.
The dsrm
utility can be used to delete any type of
object (no limitations based on object type as with
dsadd
and dsmod
). The only
required parameter is the DN of the object to delete. You can also
specify -noprompt
to keep it from asking for
confirmation before deleting. The -s
parameter can
be used as well to specify a specific server to target.
Using the DeleteObject
method is straightforward.
Passing 0 as a parameter is required, but does not have any
significance at present.
An alternate and perhaps safer way to delete objects is to use the
IADsContainer::Delete
method. To use this method,
you must first bind to the parent container of the object. You can
then call Delete
by passing the object class and
RDN of the object you want to delete. Here is an example for deleting
a user
object:
set objCont = GetObject("LDAP://ou=Sales,dc=rallencorp,dc=com") objCont.Delete "user", "cn=rallen"
Delete
is safer than
DeleteObject
because you have to be more explicit
about what you are deleting. With DeleteObject
you
only need to specify a distinguished name and it will delete it. If
you happen to mis-type the DN or the user input to a web page that
uses this method is mis-typed, the result could be disastrous.
Recipe 4.21 for deleting a container, MS KB 258310 (Viewing Deleted Objects in Active Directory), MSDN: IADsContainer::Delete, and MSDN: IADsDeleteOps::DeleteObject
Get Active Directory Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.