"未知名称"调用DirectoryEntry.DeleteTree时

时间:2012-01-23 19:20:49

标签: powershell active-directory

我正在尝试使用PowerShell删除AD用户和组,但是我收到“未知名称”例外。

代码:

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

结果:

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

在$ entry上调用Get-Member不会返回任何方法,只返回属性。

1 个答案:

答案 0 :(得分:1)

这应该可以解决问题:

$entry.psbase.DeleteTree()