Scripting · 2024-02-04
PowerShell Script to test multiple IP Addresses
This small scriptlet reads a CSV with a column called “IPaddress” and pings its way through the addresses. In a lot of projects I have to confirm that a set of IPs is free.
Topics capabilities · idf weight Automation automation 1.80
Vendors vendors · idf weight VMware vmware 0.91
This small scriptlet reads a CSV with a column called “IPaddress” and pings its way through the addresses.
In a lot of projects I have to confirm that a set of IPs is actually free. This scriptlet colour-codes the result and can be re-run whenever you need it, at almost no effort.
Param(
[Parameter(Mandatory=$true, position=0)][string]$csvfile
)
$ColumnHeader = "IPaddress"
Write-Host "Reading file" $csvfile
$ipaddresses = import-csv $csvfile | select-object $ColumnHeader
Write-Host "Started Pinging.."
foreach ($ip in $ipaddresses) {
if (test-connection $ip.("IPAddress") -count 1 -quiet) {
write-host $ip.("IPAddress") "Ping succeeded." -foreground green
} else {
write-host $ip.("IPAddress") "Ping failed." -foreground red
}
}
Write-Host "Pinging Completed."