title: Can I use -ErrorVariable while using Out-String in Powershell
body: <p>I'm trying to capture the output of a command into output variable in Powershell. The output of the command is in table format which is why I'm using Out-String. Now I need to suppress the error messages which is why I use an error variable to store the error messages. I tried the following things but none of them suppress my error and error gets displayed on screen.</p>
  
  <pre><code>$output = $esxcli.network.firewall.ruleset.allowedip.list() | Out-String -ErrorVariable myErr
  
  $output = $esxcli.network.firewall.ruleset.allowedip.list() -ErrorVariable myErr | Out-String
  
  $output = $esxcli.network.firewall.ruleset.allowedip.list() | Out-String 2&gt;&amp;1
  
  $output = $esxcli.network.firewall.ruleset.allowedip.list() 2&gt;&amp;1 | Out-String
  </code></pre>
  
  <p>Is there a way where I can suppress the errors while using Out-String in a simple way (nothing like try-catch)?</p>