title: Get the exact command error output displayed in console into a Powershell variable
body: <p>I'm writing some scripts to backup registry and I encountered 2 small issues. The 1st one is that I can't intercept the error output of the <code>reg export</code> command.</p>
  <p>Example:</p>
  <p><code>reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg</code></p>
  <p>Writes this to console because the key is not available:</p>
  <p><code>ERROR: The system was unable to find the specified registry key or value.</code></p>
  <p>I would love to get this <strong>exact</strong> string.</p>
  <p>Assigning the command to a variable results in an empty string, even with <code>Out-String</code>:</p>
  <p><code>$regerror = reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg | Out-String</code></p>
  <p>The closest solution I've found is this kind of redirection:</p>
  <p><code>$regerror = &amp; reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg 2&gt;&amp;1</code></p>
  <p>But that displays:</p>
  <pre><code>reg.exe : ERROR: The system was unable to find the specified registry key or value.
  At line:1 char:9
  + $test = &amp; reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg  ...
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (ERROR: The syst...y key or value.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
  </code></pre>
  <p>I'm wondering if there's a simple way to get the mentioned exact output without attempting to process the text above.</p>