Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell Test-Connection

The benefits of Test-Connection are two-fold, you can measure average response times, something that's not possible with ping, and you can employ Test-Connection as a vehicle for learning about PowerShell's mathematical cmdlets such as Measure-Object and [System:Math].

Topics for PowerShell Test-Connection

 ♣

Test-Connection Measures Response Time for Website

Ping has been the traditional command to test connectivity.  My mission is to show how PowerShell can achieve better control through its cmdlet Test-Connection.

Getting Started: Switch from Ping to Test-Connection

Assumption: You not only have installed and setup PowerShell, but also it's PowerShell v 2.0 and not v 1.0.

# PowerShell's Test-Connection - Equivalent of Ping
ping computerperformance.co.uk

# Now launch PowerShell and try:
Test-Connection computerperformance.co.uk

Benefits of Test-Connection Compared to Ping

This following script contains 3 elements:
1) Test-Connection (Ping)
2) Measure-Object to calculate the average.
3) A static method called System.Math, which we'll use to round the number of milliseconds. 

There is no doubt that you could make a much more efficient script, however my version pays homage to divide and rule.  I believe that the easiest way to learn scripting is to break the task into chunks, then bolt all the bits together.  Furthermore, my version encourages you to make alterations, for example, change the value of $Server and the number of tests to 'count'.

# PowerShell script to measure a server's response time
Clear-host
$Avg = 0
$Server = "www.computerperformance.co.uk"
$PingServer = Test-Connection -count 3 $Server
$Avg = ($PingServer | Measure-Object ResponseTime -average)
$Calc = [System.Math]::Round($Avg.average)
Write-Host "Average response time to $Server is $Calc ms"

Note 1:  Test-Connection is more flexible than Ping.  You can research more properties for your scripts by prefixing Get-Help to Test-Connection, also try suffixing Get-Member.

Note 2:  ResponseTime is a property of Test-Connection, the benefit of using this PowerShell cmdlet rather than ping is that we can calculate average connection times.

Note 3:  At first sight [System.Math]:: seems a strange way to call for mathematical functions such as Round, Truncate or log, however you soon get used to its ways!

Note 4:  See more on Measure-Object

Experiment:  You cannot learn without making mistakes, try changing the parameters below, some will make no sense, while others will be predictable.  Only by experimenting will you truly understand how to handle PowerShell's math functions.

ResponseTime -Sum (Also -Maximum, -Count)
Round($Avg.count) (Also .Maximum  .Count  .Sum) 

Guy Recommends: A Free Wake-On-LAN UtilitySolarwinds Wake-On-LAN

Encouraging computers to sleep when not in use is a great idea - until you are away from your desk and need a file on that remote sleeping machine!

Wake-On-LAN really will save you that long walk to awaken a hibernating machine; however my reason for encouraging you to download this utility is just because it's so much fun sending those 'Magic Packets'.  As Wake-On-LAN (WOL) is free, see if I am right, and you get a kick from arousing those sleeping machines.  WOL also has business uses for example, wakening machines so that they can have their patches applied. 

Download your free copy of Wake-On-LAN

Summary of Test-Connection

One of the most attractive reasons for giving PowerShell a try is that you can still use familiar cmd.exe command such as ipconfig /all and ping in PowerShell.  Once started you, can build on existing knowledge and soon achieve higher levels of skill than were possible with cmd.exe. 

Taking ping as example, you can use the same switches that you used in DOS, but better still, switch to PowerShell's equivalent called Test-Connection.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tutorials:

PowerShell Home   • Test-ServerHealth  • Test-SystemHealth   • Test-Connection  • Test-Path

PowerShell Logon Script  • PowerShell add printer  • PowerShell Schedule Task

Map Network Drive  • Exchange 2010 PowerShell Cmdlets   • Exchange 2010 Performance Monitor

Please email me if you have a better script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.