Subscribe to Windows IT Pro
September 09, 2010 12:01 AM

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

Windows IT Pro
InstantDoc ID #125886
Rating: (2)

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? Why not submit it to Don? Post your question at windowsitpro.com/go/SubmitFAQ and you might see your answer online! Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.