liveBook · Manning

-ErrorAction

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

-ea is a PowerShell parameter alias for -ErrorAction.

-ErrorAction is a PowerShell common parameter for deciding how a command responds when an error occurs. Its alias is -ea, which is handy at the prompt but easy to miss in help. section 4.6.2

Choose the behavior that matches the task:

  • Use -ErrorAction Stop when a failure should interrupt the current operation and allow Try/Catch handling. section 24.4
  • Use -EA SilentlyContinue only for errors you have deliberately decided do not matter, such as deleting an already-missing file. section 24.2
  • Continue processing while recording failures with -ErrorVariable, appending to existing data when necessary. section 24.4

Discover and use the alias

Inspect a command's parameter metadata to find the alias, then run `Get-Process -ea Stop`. Tab completion can reveal -ea after typing `Get-Process -e`, although help does not show that it equals -ErrorAction. section 4.6.2

PS /Users/james> (get-command get-process | select -Expand 
 parameters).erroraction.aliases

Inspect the parameter metadata to discover aliases that ordinary command help does not display. section 4.6.2

Handle a remote connection failure

For several computers, use `-ErrorAction Stop` inside a `foreach` loop when each connection should be attempted independently, or capture failures with `-ErrorVariable`. Wrap stopping operations in Try/Catch so the Catch block can warn the user. section 24.4

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains alias discovery, suppression risks, remote-processing choices, ErrorVariable, and Try/Catch, but not parameter implementation internals.
Examples
Uses Get-Process, Remove-Item, remote PSSession creation, service-state checks, and a remote uptime function.
What it assumes
Assumes basic PowerShell commands and parameters while teaching common-parameter aliases and error-handling choices directly.
What you can do after
Apply it via PowerShell commands to choose deliberate error behavior and build logging or Try/Catch handling.
How it connects
Connects common parameters with ErrorVariable, Try/Catch, exceptions, remoting, and error logging.

Also explained in

Compare how 3 books explain -ErrorAction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.