title: Powershell-else in try/catch
body: <p>I'm trying to write output when <code>get-addomain</code> succeded.</p>
  
  <p>Try/catch writes output only if command fails</p>
  
  <pre><code>try {
  
  get-addomain -Identity  d.contoso.com  
  
  }
  
  catch {
  
  Write-Output "failed"
  
  }
  </code></pre>
  
  <p>I tried following:</p>
  
  <pre><code>if (-not (get-addomain -Identity  d.contoso.com))
  {
  return "failed"
  }
  
  else
  
  {
  write-output "ok"
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>If (get-addomain -Identity  d.contoso.com  )
  {
      Write-Output "ok"
  }
  Else
  {
      write-output "failed"
  }
  </code></pre>
  
  <p>but in both cases got</p>
  
  <pre><code>get-addomain : Cannot find an object with identity: 'd.contoso.com' under: 'DC=ad,DC=contoso,DC=com'.
  </code></pre>