HOWTO: ping list of hosts from a file and output to txt

I used to do this with a batch file and for some reason it didnt work on Windows 7 SP1 today. So i asked a colleague for a powershell way to do this quickly. Props to Robert Ramsay over at NAMMCAL with the script.

copy the following and save in the c:\scripts folder as ping.ps1

$names = Get-Content “C:\scripts\list.txt”
foreach ($name in $names) {
if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue ) {
Write-Host “$name is up” -ForegroundColor Magenta
else {
Write-Host “$name is down” -ForegroundColor Red


Next you will need to open a administrator elevated Powershell command prompt and set your execution level to unrestricted

set-executionpolicy unrestricted

Next in your powershell window you can change directory to c:\scripts and type ./ping.ps1 > output.txt and it will save the output to the file.  DONE