A while ago someone on TE mentioned starting a thread as a repository of the scripts we have created that we find useful. At the time I kinda'a thought it would be a cool idea but decided to let someone else start it. But here it goes:
1. Post only scripts you have written.
2. Title your post with the language and purpose.
3. Do not copy someone else's stuff!
I'm sure webmaster might have something else to add.
Here is my first offering. I love the ability in Linux to pipe the ping out put to ^G and get an audible response when the host comes back. How many times have I had to reboot a server and then do a ping -t waiting for it to comeback. I continue working, an waite for the reply. Now I can here the reply... I know it could be less verbose. But I like to keep my code wordy for learning purposes.
#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"
Elemental SQL: PowerShell Scripts to Continuously Ping a Host and Give an Audible Alert