用 PowerShell 发送 Ping(Test-Connection)

PowerShell 原生的 ping:一行命令同时 ping 多台主机,返回可筛选、可脚本化的结构化结果。

Windowsping 连通测试故障排查PowerShell低风险
运行 Test-Connection example.com -Count 4 即可发送 4 次 ping,并为每次响应返回结构化对象。

01命令

命令
$ Test-Connection example.com, gateway.local -Count 4

02作用说明

Test-Connection 返回包含 Address、ResponseTime、Status 等属性的对象,因此“ping 整个网段然后只列出在线主机”这类需求变成一条管道即可完成,不用解析文本。它一次调用就能接受多个目标;注意 PowerShell 7 中参数是 -TargetName(Windows PowerShell 5.1 用 -ComputerName)。配合 -Quiet 只返回 True/False,方便写条件判断。

03风险

风险低风险

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Test-Connection - PowerShell - SS64
    SS64 · technical · 2026-09-17
    依据: SS64 documents Test-Connection as sending ICMP echo requests to one or more computers, accepting a list of targets and a -Count parameter, and returning status objects usable in pipelines.

最后验证: 2026-09-17 · 分类: 网络

06相关方案