Q. How do I use Test-Connection in PowerShell?

This cmdlet basically uses WMI's Win32_PingStatus under the hood. It returns, by default, four "result" objects, each of which contains various properties, including a StatusCode, which will be 0 for successful pings.

Don Jones

September 8, 2010

1 Min Read
connect button on a white keyboard

Q. How do I use Test-Connection in PowerShell?

A. This cmdlet basically uses WMI's Win32_PingStatus under the hood. It returns, by default, four "result" objects, each of which contains various properties, including a StatusCode, which will be 0 for successful pings. Sometimes, you just want to know if it worked or not, without all that extra information. In those cases, use:

Test-Connection remotehost -quiet

And you'll get back a simple True or False, which can be used in an If construct:

If (Test-Connection remotehost -quiet) { Write 'Reachable!'}

Do you have a Windows PowerShell question? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like