I would like to script a dcdiag test to alert me if it finds any errors. I thought I may able to do this in powershell by...
$test = dcdiag 2>$err
I don't have any errors from dcdiag at the moment so I couldn't test that directly, but I wrote another ps script to throw an exception hoping I could test this method using that script. This didn't work using the method above so I opted for
try{$test = dcdiag}catch{$err = $_.Exception.Message}
It worked for my test case, but I don't know if this will pick up stderr from dcdiag.
I would like to know how I should best achieve stderr redirect to a variable in powershell given I would like to use it with dcdiag?