It was my understanding that anything that writes to $error should be re-directable to $null, but I can't make it work, even with something as simple as substring or a bad cmdlet name:
PS C:\WINDOWS\system32> asdf 2>$null asdf : The term 'asdf' is not recognized as the name of a cmdlet... All of the examples here do not seem to work: Redirecting output to $null in PowerShell, but ensuring the variable remains set
PS C:\WINDOWS\system32> $qwerty = "a" PS C:\WINDOWS\system32> $qwerty.substring(0,2) 2>$NULL Exception calling "Substring" with "2" argument(s): "Index and length... PS C:\WINDOWS\system32> $qwerty.substring(0,2) | out-null Exception calling "Substring" with "2" argument(s): "Index and length...
$blah.substring(0,2) 2>$null Exception calling "Substring" with "2" argument(s): "Index and length must... etc.The error message is still outputting to the console rather than to the $NULL variableget-command asdf 2>$nullget-command $blah.substring(0,2) 2>$null Exception calling "Substring" with "2" argument(s): "Index and length...Didn't work