Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Removing Active Directory Nodes

Visual Studio .NET 2003

The DirectoryEntry component gives the administrator the ability to remove objects within a directory or entire directory subtrees from the hierarchy.

  • To remove a child entry from children collection of the current parent directory, call the Remove method. The Remove method takes only one argument, the entry name to be removed, and must be used only on an empty container or an object which is not used as a container for a directory tree, such as printers or computer nodes.
  • To delete an entry and all of its children, call the DeleteTree method. The DeleteTree method deletes the current entry and all of its subtree entries from the hierarchy.

To delete a child entry

  • Bind an instance of the DirectoryEntry class to the parent directory and call the Remove method. For more information, see Creating DirectoryEntry Component Instances.
    ' Visual Basic
    Dim entry As New DirectoryServices.DirectoryEntry("WinNT://DomainName")
    Dim entryToRemove As DirectoryServices.DirectoryEntry
    ' Add code here to set entryToRemove to the entry you want to remove.
    entry.Children.Remove(entryToRemove)
    
    // C#
    System.DirectoryServices.DirectoryEntry entry = 
       new System.DirectoryServices.DirectoryEntry("WinNT://DomainName");
    System.DirectoryServices.DirectoryEntry entryToRemove = null;
    // Add code here to set entryToRemove to the entry you want to remove.
    entry.Children.Remove(entryToRemove);
    

To delete an entire subtree

  • Bind an instance of the DirectoryEntry class to the parent directory and call the DeleteTree method. For more information, see Creating DirectoryEntry Component Instances.
    ' Visual Basic
    Dim entry As New DirectoryServices.DirectoryEntry("WinNT://DomainName")
    entry.DeleteTree()
    
    // C#
    System.DirectoryServices.DirectoryEntry entry = 
       new System.DirectoryServices.DirectoryEntry("WinNT://DomainName");
    entry.DeleteTree();
    

See Also

Introduction to Active Directory Objects | Walkthrough: Adding Active Directory Objects | Modifying Object Properties in an Active Directory Hierarchy | Creating DirectoryEntry Component Instances

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.