Saturday, October 30, 2010

PowerShell Scripts to Continuously Ping a Host and Give an Audible Alert

#Used to continuously ping a host and get an audible alert when it is back up.

function ContinuousPing-Beep
{
    param([string]$computer)
    $ping = new-object System.Net.NetworkInformation.Ping
    $result = $ping.Send($computer);
    if($result.Status -eq "Success")
    {
        Write-Host "Reply received from $computer" -Foreground green
        Write-Host `a;
    }
    else
    {
        do{$result = $ping.Send($computer);Write-Host "Reply from $computer. Destionation host unreachable." -Foreground red}
            until($result.Status -eq "Success")
            Write-Host "Reply received from $computer" -Foreground green
            Write-Host `a;
    }
}

function ContinuousPing-Voice
{
    param([string]$computer)
    
    $voice = new-object -com SAPI.SpVoice
    $ping = new-object System.Net.NetworkInformation.Ping
    $result = $ping.Send($computer);
    if($result.Status -eq "Success")
    {
        $voice.Speak("Reply received from $computer", 1)
    }
    else
    {
        do{$result = $ping.Send($computer);Write-Host "Reply from $computer. Destionation host unreachable." -Foreground red}
          until($result.Status -eq "Success")
       
        $voice.Speak("Reply received from $computer", 1)

    }
}

ContinuousPing-Beep "192.168.1.1"

ContinuousPing-Voice "192.168.1.1"

1 comments:

Pash said...

Very nice Rob.

Cheers,

Pash

Post a Comment