connect button on a white keyboard

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

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

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.