4
Apr 14

At my company we are about to perform and full power shutdown and I wanted to create a script to shutdown the servers.  I have never used test-connection before so this is what I came up with.

$servers = get-content -path 'c:\rcj\scripts\powershell\servers.txt'
$outfile = 'c:\rcj\scripts\powershell\servershutdownresults.txt'
foreach($server in $servers)
{
if(test-connection $server -count 1 -quiet)
{
write-output "$server is pingable" | out-file -append -filepath $outfile
}
else
{
write-output "$server is down" | out-file -append -filepath $outfile
}
}

Leave a Reply