"Unknown name" when calling DirectoryEntry.DeleteTree

0

I'm trying to delete AD users and groups with PowerShell, however I'm getting an "Unknown name" exception.

Code:

function RemoveADEntry($dn) {
    $entry = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$dn")
    $entry.DeleteTree()
}

Result:

Exception calling "DeleteTree" with "0" argument(s): "Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))"
At :line:9 char:18
+   $entry.DeleteTree <<<< ()

Calling Get-Member on $entry doesn't return any methods, only properties.

powershell
active-directory
asked on Stack Overflow Jan 23, 2012 by lzm

1 Answer

1

this should do the trick:

$entry.psbase.DeleteTree()
answered on Stack Overflow Jan 24, 2012 by dhorn

User contributions licensed under CC BY-SA 3.0