Tag Archives: powershell ping multiple hosts

[PS] Simple Powershell script to ping multiple computers

Hello world!

Simple script i wrote just to ping (test-connection to) multiple servers/computers. It uses a textfile as an input. Make sure to put one server/computer on each line in the textfile. Could probably be written 10 times cleaner, but it works.

Edit:

Modified the first script so that you could add the servers/computers directly into the script.



Computers/servers is located in a txt-file:

$path = "C:\computernames.txt"
do{
$pclist = Get-Content $path
foreach ($pc in $pclist) {
if (test-Connection -ComputerName $pc -Count 2 -Quiet ) {
Write-Host $pc is online -ForegroundColor Green
} else {Write-Host $pc is offline -ForegroundColor Red}
}
} until($forever)

 

Computers/servers are located in the script:


$pclist = "computer1", "computer2", "computer3", "computer4", "computer5"
do{
foreach ($pc in $pclist) {
if (test-Connection -ComputerName $pc -Count 2 -Quiet ) {
Write-Host $pc is online -ForegroundColor Green
} else {Write-Host $pc is offline -ForegroundColor Red}
}
} until($forever)

 

If you want more beginner-friendly commands, check out my new article

[PS] Top Ten Simple Powershell commands every IT-admin should know

 

6 1