Dec 13 2023 10:43 AM
I have a remediation script that runs with the users credentials. The script appears to do what it is supposed to do BUT... it is also throwing this error:
System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: An error occurred while performing the specified operation. See the error details for more information.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
I am catching the error in an error variable via -ErrorVariable and saving that to a file but the above is all I'm getting. Any idea what this error actually represents?
Dec 14 2023 01:22 AM
Hi @KevinWGagel,
The error message you’re seeing is System.Management.Automation.ActionPreferenceStopException.
This exception is thrown when a PowerShell command is stopped because the preference variable “ErrorActionPreference” or a common parameter is set to “Stop”. This usually happens when an error occurs while performing the specified operation.
The error message suggests that an operation in your script is failing, and because the “ErrorActionPreference” is set to “Stop”, it’s halting the execution of the script at that point.
The specific operation that’s failing isn’t clear from the error message alone.
To troubleshoot this issue, use the following steps:
The goal is to identify the operation that’s causing the error, and then understand why it’s failing.
You can check these links for more information:
ActionPreferenceStopException Class (System.Management.Automation) | Microsoft Learn
Import-Module : Could not load file or assembly 'System.Management.Automation - Microsoft Q&A
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
Dec 19 2023 08:57 AM