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 reg export command.
Example:
reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg
Writes this to console because the key is not available:
ERROR: The system was unable to find the specified registry key or value.
I would love to get this exact string.
Assigning the command to a variable results in an empty string, even with Out-String:
$regerror = reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg | Out-String
The closest solution I've found is this kind of redirection:
$regerror = & reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg 2>&1
But that displays:
reg.exe : ERROR: The system was unable to find the specified registry key or value.
At line:1 char:9
+ $test = & reg export HKEY_CURRENT_USER\Software\OpenVPN-GUI test.reg ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR: The syst...y key or value.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
I'm wondering if there's a simple way to get the mentioned exact output without attempting to process the text above.