当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell:如何同时 ping 多台计算机

作者:精品下载站 日期:2024-12-14 05:32:31 浏览:13 分类:玩电脑

PowerShell:如何同时 ping 多台计算机


您想同时 ping 多台计算机吗?不能?是的,您可以使用 PowerShell。在这篇文章中,我将向您展示一些如何 ping 多台计算机的示例。我们将使用 Test-Connection cmdlet 来完成此任务。这将会是令人兴奋的。让我们开始吧。

打开 PowerShell 5.1 或 PowerShell 7。

示例 1:Ping 多台计算机

Test-Connection -ComputerName a-d.site,192.168.0.1,microsoft.com -Count 1

[玩转系统] PowerShell:如何同时 ping 多台计算机

示例 2:Ping 所有域计算机

 Test-Connection -ComputerName (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name) -Count 1

[玩转系统] PowerShell:如何同时 ping 多台计算机

示例 3:从文本文件 Ping 计算机

Test-Connection -ComputerName (Get-Content C:\Data\Computers.txt) -Count 1

[玩转系统] PowerShell:如何同时 ping 多台计算机

示例 4:子网 Ping

请注意,由于 -Parallel 参数的存在,这仅适用于 PowerShell 7

# PowerShell 7
$subnet = '192.168.0.'
$ips = 1..254
$ips | ForEach-Object -Parallel {
    Test-Connection -ComputerName $using:subnet$_ -Count 1 
}

[玩转系统] PowerShell:如何同时 ping 多台计算机

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯