title: Convert Test-Connection into Boolean
body: <p>I am using Powershell version 2, so I am unable to use Ping-Host as explained here
  <a href="https://stackoverflow.com/questions/1595298/is-there-a-way-to-treat-ping-host-as-a-boolean-in-powershell">Is there a way to treat Ping-Host as a boolean in PowerShell?</a></p>
  
  <p>I can use test connection, i.e.</p>
  
  <pre><code>Test-Connection *ip_address* -count 1
  </code></pre>
  
  <p>I am trying to make this into a boolean, but it is not working</p>
  
  <pre><code>if ($(test-connection server -count 1).received -eq 1) { write-host "blah" } else {write-host "blah blah"}
  </code></pre>
  
  <p>The server I am able to ping outputs "blah blah", as if I am not able to ping it.</p>
  
  <p>On the other hand, if I ping an unreachable server, I get error message</p>
  
  <blockquote>
    <p>Test-Connection : Testing connection to computer <em>server</em> failed:
    Error due to lack of resources At line:1 char:22
    + if ($(test-connection &lt;&lt;&lt;&lt;  <em>server</em> -count 1).received -eq 1) { write-host "blah" } else {write-host "blah blah"}
        + CategoryInfo          : ResourceUnavailable: (<em>server</em>:String) [Test-Connection], PingException
        + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand</p>
  </blockquote>
  
  <p>And at the end it still outputs "blah blah".</p>
  
  <p>How to fix?</p>