Is there a way to treat Ping-Host as a boolean in PowerShell?

回眸只為那壹抹淺笑 提交于 2019-12-08 18:33:24

Something like this?

if ($(Ping-Host server1 -count 1 -timeout 10).received -eq 1) { blah }

If you are on PowerShell 2.0 I would recommend using Test-Connection -Quiet. It returns a simple true or false indicating whether or not the host can be reached via ping. BTW one of the benefits of Test-Connection is it's built-in whereas ping-host isn't.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!