title: Powershell Try/catch - get-user
body: <p>I'm learning <code>posh</code>. And I'm trying to understand why this script doesn't catch the warning.</p>
  
  <pre><code>try{
      get-user aaaa -WarningAction Stop
  }
  catch
  {
      Write-Host "hi"
  }
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>get-user : The operation couldn't be performed because object 'aaaa' couldn't be found on
  'iDC01.contoso.com'. At C:\Users\Gra***\Desktop\test.ps1:2 char:5
  +     get-user aaaa -WarningAction Stop
  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Get-User], ManagementObjectNotFoundException
      + FullyQualifiedErrorId : [Server=ME1,RequestId=ebcde0d2-9222-443b-b25a-ef7279fd168e,
        TimeStamp=20.06.2017 13:51:35] [FailureCategory=Cmdlet-ManagementObjectNotFoundException]
        FE0D594D,Microsoft.Exchange.Management.RecipientTasks.GetUser
  </code></pre>
  
  <p>I've tryied <code>-WarningActions Stop</code> and <code>-ErrorAction Stop</code> but no results.</p>
  
  <p>In general I've understood the basics of <code>try/catch</code> and the following script works ok.</p>
  
  <pre><code>try{
  Get-Process -name xyz -ErrorAction Stop
  }
  catch{
  Write-Host "oops"
  }
  </code></pre>
  
  <p>I'm using <code>powershell_ise 5.1</code>. Do you know what's wrong with the <code>get-user</code>? 
  Also, I can't use <code>Get-ADuser</code>.</p>