Created
February 1, 2013 16:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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