title: Handle exception in powershell
body: <p>I have a config file when you can add a list of performance counters, for example :</p>
  
  <pre><code>\Memory\Page Faults/sec
  \Memory\Available Bytes
  \ASP.NET Applications(*)\Requests in Application Queue
  </code></pre>
  
  <p>I have a powershell script, that parses the file and does a Get-Counter parameter where parameter is each counter in my config file. Everything works well, but I would like my script to be able to handle exception when an user add a bad counter, for example :</p>
  
  <pre><code>\Memory\Page Faults/sec
  \Memory\Available Bytes
  \ASP.NET Applications(*)\Requests in Application Queue
  ddftrigjgigjij
  </code></pre>
  
  <p>With this, I get a red exception in my powershell console which I would like to replace with an appropiate message like "counter not found". I am beginning with powershell and I tried to use try\catch without success.</p>
  
  <p>Thanks in advance for your help.</p>