SID-500

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

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

Execute the following two-liners to cause Powershell to say “Command completed successfully”.

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

After some time I thought to myself: I could try something. PowerShell shall tell me if a host is reachable or not. All i need is a simple if statement and Test-Connection.

Copy the following code in your PowerShell Session and provide 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 …)


1 Comment

  1. […] By the way: ::1 is the IPv6 address of localhost like 127.0.0.1 in IPv4. You can also use PowerShell to talk to you: Speak to me: PowerShell tells you if a host is up or not (Test-Connection). […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Who is the blogger?

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com