Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想做这样的事情:
if (Ping-Host server1) { blah }
有谁知道一个简单的方法?
如果您使用的是 PowerShell 2.0,我建议您使用 Test-Connection -Quiet。它返回一个简单的 true 或 false 指示是否可以通过 ping 访问主机。顺便说一句,Test-Connection 的好处之一是它是内置的,而 ping-host 不是。
像这样的东西?
if ($(Ping-Host server1 -count 1 -timeout 10).received -eq 1) { blah }