Skip to content

Instantly share code, notes, and snippets.

@ddhahn
Created February 1, 2013 16:34
Show Gist options
  • Save ddhahn/4692421 to your computer and use it in GitHub Desktop.
Save ddhahn/4692421 to your computer and use it in GitHub Desktop.
Ping a list of machines and write the results to two files. machines that are alive and machines that don't respond
$machines = get-content("c:\temp\machines.txt")
foreach ($machine in $machines) {
#check for DNS resolution
$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$machine'" | Select-Object StatusCode
if ($PingStatus.StatusCode -ne 0) {
$machine | out-file "c:\temp\machinesnotthere.txt" -enc ASCII -append
write-host "couldn't ping $machine"
}
else {
$machine | out-file "c:\temp\machinesthere.txt" -enc ASCII -append
write-host "$machine responded"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment