PowerShell Response - All Errors - Check
Summary
This script takes a parent's psout
variable and checks it for known common errors, converting those errors into a human-readable format and logging them in the script log. This is particularly useful when attempting to determine why a PowerShell command didn't run as expected, and it can be instrumental in testing, troubleshooting, and the development of future scripts.
This script has been used in 12 scripts as a method of troubleshooting. It has evolved from 3 known errors to now 7, and it can be easily extended.
Sample Run
This script should always be called from a parent script.
- On any parent script where a PowerShell command is being run, save the output to the variable
@psout@
. - Run the PowerShell Response - All Errors - Check script immediately after setting the
@psout@
variable. - After running that script, check the state of the
@failstatus@
variable in the script. If the state is False, then the PowerShell command that was run triggered an error check, and a log should be present in the@EnvironmentalError@
variable.
Dependencies
- A
@psout@
variable must be present in the script at the time of calling this script.
Variables
Name | Description |
---|---|
EnvironmentalError | This variable sets the human-readable interpretation of the error held in the @psout@ variable. |
Process
- Check
@psout@
for a specific string.- Set the
@EnvironmentalError@
variable to what the specific string reflects. - Log the error and exit with an error.
- Set the
- Go back to step 1 until all known strings are queried.
- Exit the script.
Output
- Script log
@failstatus@
variable state@EnvironmentalError@
variable