我正在编写一个 powershell 脚本来 ping 所有服务器并检查哪些服务器处于脱机状态。但我有一个错误。顾名思义,它完美地工作。但是,当我使用 IP 进行测试连接时,它似乎可以工作,但我无法在哈希列表中输出 IP 的名称。有人可以帮我解决这个问题吗?谢谢!!
System.Collections.Hashtable.keys 在线/可用,这是它输出的。但我想让它说“服务器名称在线/可用”
#Creating IP Array list
$ip_array = @{
Server = [ipaddress] "192.168.1.1"
sws = [ipaddress] "192.168.1.1"
}
Foreach ($ip in $ip_array)
{
if((Test-Connection -IPAddress $ip.values.ipaddresstostring -quiet -count 1 ) -eq $false)
{
write-output("$ip.keys Is offline/unavailable, please troubleshoot connection, script is terminating") | Red
}
else
{
$ping = $true
write-output("$ip.keys Is online/available") | Green
}
}