title: Handle command prompt error within PowerShell script
body: <p>I am trying to run a few command prompt commands like <code>schtasks</code> within a PowerShell script. I would like to know how to handle errors thrown by the command in PowerShell.</p>
  
  <p>I tried:</p>
  
  <ul>
  <li><code>&amp; cmd.exe /c 'schtasks /Query /TN xx || echo ERROR'</code></li>
  <li><code>&amp; cmd.exe /c 'ping.exe 122.1.1.1 &amp;&amp; exit 0 || exit 1'</code></li>
  <li><code>Invoke-Expression -Command:$command</code></li>
  </ul>
  
  <p>I'm unable to run these commands and ignore or catch exception in a <code>try..catch</code> block of the PowerShell script. I know there are libraries but I'm limited to PowerShell v2.0.</p>