Showing posts with label Test-Commection GWMI Measure-object. Show all posts
Showing posts with label Test-Commection GWMI Measure-object. Show all posts

Tuesday, January 4, 2011

Using Test-Connection

'Test-Connection' is Powershell V2's GWMI-based icmp test cmdlet that returns considerable amounts of information in object format.  'Test-Connection' also has the ability to authenticate (at various levels) to the computer whose ICMP responses it is testing, but I do not discuss that in this post. 'Test-Connection' can return a number of errors, which I found difficult to trap, throw, or try-catch-finally.  So, like some others (1,2), I punted on error-trapping with:
 [string] $ErrorActionPreference="silentlycontinue"  (Yea, I know...what a wimp...) 
Although, 'Test-Connection' is slower than System.Net.NetworkInformation.Ping will probably ever be, it does return considerable amounts of useful information. Below is the function 'Ping-IP' with the returned object and some statistical results from 'measure-object'. I've created a hash table and renamed six of the properties.  Notice how I can use 'Test-Connection' to check for IPv4 and IPv6 connections simultaneously (if you have an existing IPv6 interface).