powershell 清單ping

參考節錄:

https://www.weithenn.org/2021/07/powershell-ping.html?fbclid=IwAR0vtSQS_CRZiBNDSm0eOc89RQlY2Y6-hsU0OCKb7mu0Ub7yxjTLwSY0MQQ

# ==================================================================
# Description: Test ping connectivity by hosts list
# ==================================================================

# Get hosts list
$Ping_hosts = Get-Content -Path C:\PowerShell\Ping_hosts.txt

# Verify the number of hosts
(Get-Content -Path C:\PowerShell\Ping_hosts.txt).Count

# Test ping connectivity by hosts list
foreach ($Hosts in $Ping_hosts){
If (Get-ADComputer -Filter {Name -eq $Hosts}){
Write-Host "$Hosts – host exists try to ping!" -ForegroundColor Green
# For PingReplyDetails (RTT) label and value
$RTT = @{Label = "PingReplyDetails (RTT)"; Expression = {$_.PingReplyDetails.RoundTripTime.ToString() + " ms"}; align="right"}
Test-NetConnection -ComputerName $Hosts | Format-Table ComputerName, RemoteAddress, PingSucceeded, $RTT -AutoSize
} else {
Write-Host "$Hosts – name resolution failed!" -ForegroundColor Red
}
}

本篇發表於 未分類。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>