任何人都可以告诉我以下代码有什么问题。我正在尝试从AD中清除已删除的帐户。
Function Del-User() {
$To_Be_Deleted = (Get-ADObject -Filter 'isDeleted -eq $True -and -not (isRecycled -eq $true) -and name -ne "Deleted Objects" -and lastKnownParent -eq "CN=Users,DC=example,DC=local"'-includeDeletedObject).DistinguishedName
foreach ($d in $To_Be_Deleted) {
Remove-ADObject -Identity $d
}
}
Del-User
当我将输出直接传送到Remove-ADObject
时,它可以正常工作,但是当我尝试使用该功能时它不起作用,我收到以下错误:
At C:\Users\administrator.example\Documents\del.ps1:18 char:9 + Remove-ADObject -Identity $d + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (CN=user name...example,DC=local:ADObject) [Remove-ADObject], ADIdentityNotFoundException + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.RemoveADObject Remove-ADObject : Directory object not found