Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does an error still show when I specify -ErrorAction SilentlyContinue?

Tags:

powershell

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

The code says it all.

like image 808
Caleb Jares Avatar asked Jun 25 '12 22:06

Caleb Jares


2 Answers

The ErrorAction ubiquitous parameter can be used to silence non-terminating errors using the parameter value SilentlyContinue and it can be used to convert non-terminating errors to terminating errors using the parameter value Stop. However it can't help you ignore terminating errors and in this case Stop-Transcript is throwing a terminating error. If you want to ignore, use a try/catch e.g.:

try { Stop-Transcript } catch {}
like image 192
Keith Hill Avatar answered Sep 23 '22 02:09

Keith Hill


You can use Trap {Continue} Stop-Transcript instead to avoid any errors.

like image 34
de.coding.myth Avatar answered Sep 24 '22 02:09

de.coding.myth