Tonight I wrote a short Powershell script to have PowerShell go through a list of servers and report back which are up. Just for fun I thought I would add in a couple of lines to make PowerShell tell me which servers are down by using the voice functions available and by highlighting the down servers with a red background.
I know, it's not groundbreaking but I like it!
Here is the code.
cls
$Voice = new-object -com SAPI.SpVoice
function Ping-Host {
BEGIN {}
PROCESS {
$results = gwmi -query "SELECT * FROM Win32_PingStatus WHERE Address = '$computer'"
if ($results.StatusCode -eq 0) {
Write-Host "$computer is Pingable"
} else {
$Voice.Speak( "Alert Alert Alert $computer is down", 1 )
Write-Host "$computer is not Pingable" -BackgroundColor red
}
}
END {}
}
$computers = Get-Content q:\servers.txt
foreach ($computer in $computers) {
if (Ping-Host $computer) {
}
}
The output looks like this:
All i'm doing is listing a bunch of servers in Q:\Servers, then piping each one through a ping and outputing on screen the servers that respond and the ones that don't go to the screen with a red background and to the voice thingy that talks like in war games.
Right now to me this is the coolest thing I have made in PowerShell.