Question: Why the variable $errProcess is empty with the common parameter -ErrorVariable ?
Not working
Working
The content of the variable $errProcess should contain the error:
Answer :
1 2 3 4 5 6 7 8 9 10 11 12 |
# Answer: # To overwrite the variable errProcess Get-Process -Id 999999 -ErrorAction SilentlyContinue -ErrorVariable errProcess # To append to the variable errProcess Get-Process -Id 999999 -ErrorAction SilentlyContinue -ErrorVariable +errProcess Even if we use a variable for ErrorVariable, errors still updating the variable $err. # Explanation: No need to use the dollar sign with the parameter -ErrorVariable. |