Extending Test-Connection

Using the Test-Connection in an enterprise environment, I often miss the -a parameter of the old ping command, that tells ping to try to resolve IP address to HostName.

So I sat down and created a proxy function for Test-Connection, adding a Resolve parameter. It’s quite simple actually, it’s checks the ComputerName parameter, and if the data is a valid IP address tries to resolve using the Net.Dns class. It then takes the resolved name and injects it back into the ComputerName parameter before calling the original Test-Connection command.

There is one drawback of using proxies with the same name as existing commands though, and that is that Get-Help with not work as you are used to. There is two ways of “fixing” this problem:

  1. Call Get-Help like this:
    Get-Help Test-Connection -Category Function
  2. Add the following line to your PowerShell profile:
    (Get-Command Microsoft.PowerShell.Management\Test-connection).Visibility = 'Private'

Code:

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