Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created September 24, 2024 03:52
Show Gist options
  • Select an option

  • Save dieseltravis/08643fcc6af2aeaf6ccead6b359c0f42 to your computer and use it in GitHub Desktop.

Select an option

Save dieseltravis/08643fcc6af2aeaf6ccead6b359c0f42 to your computer and use it in GitHub Desktop.
ping a list of domains to see how they perform, whether they're up or down
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
wikipedia.org
www.wikipedia.org
en.wikipedia.org
eo.wikipedia.org
$csvoutput = @()
$txtdomains = Get-Content "domains.csv"
$count = 10
$bufferbytes = 10000
$delayseconds = 1
$timeoutseconds = 30
Write-Host "Name,Avg,Min,Max,StDev,Fails,Status"
foreach ($name in $txtdomains) {
$results = Test-Connection -ComputerName $name -Count $count -ErrorAction SilentlyContinue -BufferSize $bufferbytes -Delay $delayseconds -TimeoutSeconds $timeoutseconds
$fails = ($results | Where-Object { $_.Status -ne "Success" }).Length
$stats = $results | Where-Object { $_.Status -eq "Success" } | Measure-Object -Property "Latency" -Minimum -Maximum -Average -StandardDeviation
$avg = [math]::Round($stats.Average, 1)
$min = [math]::Round($stats.Minimum, 1)
$max = [math]::Round($stats.Maximum, 1)
$std = [math]::Round($stats.StandardDeviation, 1)
$row = ''
if ($fails -lt $count) {
$row = "$name,$avg,$min,$max,$std,$fails,Up"
} else {
$row = "$Name,*,*,*,*,$fails,Down"
}
$csvoutput += $row
Write-Host $row
}
$csvoutput | Out-File "domains-results.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment