有多种途径使用Ping命令检查电脑连接,这里有个简单的方法使用早期的ping.exe工具,它能很方便的集成到你的脚本里:
function Test-Ping { param([Parameter(ValueFromPipeline=$true)]$Name) process { $null = ping.exe $Name -n 1 -w 1000 if($LASTEXITCODE -eq 0) { $Name } } }
Test-Ping函数能接受电脑名、IP地址, 如果成功将返回结果。这种方式,你能得到查询更多电脑和IP,得到在线的:
'??','127.0.0.1','localhost','notthere',$env:COMPUTERNAME | Test-Ping
原文地址:Pinging Computers
本文链接: https://www.pstips.net/pinging-computers.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!