0

我正在尝试运行一些如此基本的东西,以至于被问到有点尴尬......无论如何,希望有人会指出它并烤我。;-)

$PCs = Get-ADComputer -Filter {enabled -eq "True"} -SearchBase "OU=Domain servers,DC=company,DC=com"

foreach ($PC in $PCs)

{
if (Test-Connection -ComputerName $PC -Count 1)
{
write-host "online and do this" -ForegroundColor DarkGreen -BackgroundColor White
}
else {
    {
}
write-host "offline and skip doing this" -ForegroundColor Red -BackgroundColor White
}
}

我不断收到每个条目的错误:

测试连接:测试与计算机 'CN=svr1,OU=Servers,OU=Domain Servers,DC=company,DC=com' 的连接失败:不知道这样的主机

我知道我之前“成功”地做到了这一点,但我正在做一些深夜的事情,并希望很快能看到一些东西。

4

1 回答 1

0

这应该可以解决问题:

改变这个: if (Test-Connection -ComputerName $PC -Count 1)

为了这: if (Test-Connection -ComputerName $PC.Name -Count 1)

编辑:在不调用属性名称的情况下,Test-Connection 使用每个对象的位置 0 (DistinguishedName) 作为输入参数。

错误本身是因为 DNS 无法将 DN 解析为 IP,因此您需要传递要 ping 的计算机的名称或完全限定域名。

于 2021-03-16T23:27:15.513 回答