PowerShell

Speak to me: PowerShell tells you if a host is up or not (Test-Connection)

Execute the following two-liners to cause PowerShell saying “Command completed successfully”.

$words = New-Object -ComObject SAPI.SpVoice
$words.speak("Command completed successfully")

So I came up with an idea. PowerShell shall tell me if a host is up or not. All I need is a simple if statement and Test-Connection.

Copy the following code in your PowerShell Session and enter a hostname or IP Address (for example: sid-500.com):

$IPorName=Read-Host "IP Address or Name of Remote Host?"
$up="$IPorName is up"
$words=New-Object -ComObject SAPI.SpVoice
If (Test-Connection $IPorName -Quiet -Count 1)
{$null=$words.Speak($up)}
else 
{Write-Host "Host is down"}

To find all voices type

$words.GetVoices() | Foreach-Object {$_.getdescription()}

Unbenannt.JPG

I wish all my readers a nice weekend!

See also my articles about Test-Connection and Test-NetConnection: The modern version of ping: Test-Connection and PowerShell: Playing with Test-NetConnection (ping, tracert, TCP Ports …)

Categories: PowerShell

Tagged as: ,

2 replies »

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.