我希望我的PowerShell脚本在我运行的任何命令失败时停止(例如set -e在bash中).我正在使用Powershell命令(New-Object System.Net.WebClient)和程序(.\setup.exe).
PS C:\Users\ad_ctjares> Stop-Transcript -ErrorAction silentlycontinue
Transcription has not been started. Use the start-transcript command to start transcription.
Stop-Transcript : An error occurred stopping transcription: The console host is not currently transcribing.
At line:1 char:16
+ Stop-Transcript <<<< -ErrorAction silentlycontinue
+ CategoryInfo : InvalidOperation: (:) [Stop-Transcript], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.StopTranscriptCommand
Run Code Online (Sandbox Code Playgroud)
代码说明了一切.