Caleb Jares
Caleb Jares

Reputation: 6307

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

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.

Upvotes: 8

Views: 10698

Answers (2)

de.coding.myth
de.coding.myth

Reputation: 125

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

Upvotes: 3

Keith Hill
Keith Hill

Reputation: 201882

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 {}

Upvotes: 14

Related Questions