We have below az storage blob upload
command in a powershell script named upload_file.ps1
that uploads a file to Azure storage as a blob.
$ErrorActionPreference = "Stop"
# Blob connection string parsed from a secure string
az storage blob upload --container-name "ftp" --connection-string "$blobConnStr" --name "testfile.txt" --file testfile.txt
There is no problem when executing this script directly. But after converting it into a Windows executable upload_file.exe
using this PS2EXE tool, the execution fails with below exception.
ERROR: System.Management.Automation.PSInvocationStateInfo
ERROR: System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "
ErrorActionPreference" or common parameter is set to Stop: System.Management.Automation.RemoteException
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)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToPro
cess)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
ERROR: Failed
ERROR: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: S
ystem.Management.Automation.RemoteException
To print out above verbose level message, I modified the ps2exe.ps1
script a bit as below.
if (powershell.InvocationStateInfo.State == PSInvocationState.Failed) {
ui.WriteErrorLine(powershell.InvocationStateInfo.ToString());
ui.WriteErrorLine(powershell.InvocationStateInfo.Reason.ToString());
ui.WriteErrorLine(powershell.InvocationStateInfo.State.ToString());
ui.WriteErrorLine(powershell.InvocationStateInfo.Reason.Message);
}
Not sure if there is any compatibility issue between Azure CLI and Windows executables. Would appreciate it a lot if someone with Windows experience could enlighten us on this.