【发布时间】:2014-06-04 23:05:40
【问题描述】:
潜伏了很久,但我终于发现了一个我找不到答案的问题,所以我决定是时候加入了。我试图收集 AD 中早于 X 天 ($DelCompDays) 的计算机列表。然后根据 DistinguishedName 字段使用身份标志删除该计算机。问题甚至是我得到的域管理员凭据:Remove-ADComputer:访问被拒绝
即使我运行 Remove-ADComputer -Identity "Full CN or Short name" 我也会被拒绝访问。有人有想法么?提前谢谢!
#Get AD computers older than $DelCompDays
$results = Search-ADAccount -ComputersOnly -AccountInactive -TimeSpan "$DelCompDays.00:00:00"
#Loop and try to delete
foreach ($result in $results){
if ($result -ne $NULL){
try {
Remove-ADComputer -Identity $result.DistinguishedName -confirm:$false
$Success = "Deleted: $result.DistinguishedName"
WriteCustomOutput -message "$Success" -foregroundcolor green -backgroundcolor DarkMagenta
}
catch {
$Error = "Failed to delete: $result.DistinguishedName"
WriteCustomOutput -message "$Error" -foregroundcolor Red -backgroundcolor Black
}
}
else{
$Warning = "No computers older than $ArcDays days to delete"
WriteCustomOutput -message "$Warning" -foregroundcolor yellow -backgroundcolor DarkMagenta
}
}
【问题讨论】:
-
对象是否检查了意外删除位?你可以,也许,看看其中一个计算机属性 > 对象选项卡 > 查看底部的复选框吗?
-
感谢您的输入,实际上他们没有。我想通了,并在下面发布了答案。事实证明,remove-adcomputer 在非交互式运行时传递凭据的方式存在问题。 @AdilHindistan