A simple powershell script to ping multiple IPs/Hostname
How to use
Replace the value of the variable $variable (example: $variable = “ipaddress”,”hostname”,”computername”,”website”)
Copy and paste the script in notepad and save with extension “.ps1”
Run via the commandline in powershell
PS C:\Temp> .\ping.ps1
Or you can right click the file and run by “Run with PowerShell”
$variable = "facebook.com","google.com","amazon.com","nba.com"
clear
Write-Host "Not Pingable does not mean site/computer is down. It could be that ping response is disabled.`r`n" -foregroundcolor red -backgroundcolor blue
foreach ($computer in $variable)
{
if (Test-Connection $computer -Count 1 -ErrorAction SilentlyContinue){
Write-Host "$computer is " -nonewline
Write-Host "pingable" -foregroundcolor green
}
else{
Write-Host "$computer is " -nonewline
Write-Host "not pingable" -foregroundcolor red
}
}
Sample Output
No comments:
Post a Comment