PowerShell

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 up 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 …)

Categories: PowerShell

Tagged as: ,

2 replies »

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s