Stop-Transcript emits an error even if -ErrorAction SilentlyContinue is used -
Stop-transcript –ea 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 <<<< –ea SilentlyContinue
This must be a bug. Luckily, Stop-Transcript is not an important command as such.
You can suppress the error message using one of these method.
1) Set the global variable (or in the script scope)
$ErrorActionPreference="SilentlyContinue"
2) Do it locally in your script (better)
& { $ErrorActionPreference="SilentlyContinue"; Stop-Transcript }
3) Trap the message (probably best)
Trap {Continue} Stop-Transcript
If you need to suppress all output append > $null
1 comment:
great! thanks for this, I have been wondering about it.
Post a Comment