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.
this should do the trick:
$entry.psbase.DeleteTree()
User contributions licensed under CC BY-SA 3.0