liveBook · Manning

-ErrorAction

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

ErrorAction is a PowerShell common parameter that controls how a command or function responds to errors.

-ErrorAction controls how an individual PowerShell command responds when a nonterminating error occurs. Prefer command-level control over changing the global default. section 15.1

Choose the response that matches the automation goal:

  • Continue reports the error and keeps going; SilentlyContinue hides it and keeps going. section 15.1
  • Inquire asks whether to continue or stop; Stop converts the error into a terminating exception that code can catch. section 15.1
  • Ignore suppresses the error similarly to SilentlyContinue, but applies to -ErrorAction rather than $ErrorActionPreference. section 15.1

Try several responses

Get-Service -Name BITS, Nobody, WinRM -EA Stop makes the missing Nobody service catchable. Use -EA SilentlyContinue only when the failure is genuinely irrelevant. section 15.2

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Defines five practical response choices and recommends command-level control, while warning against indiscriminate suppression.
Examples
Uses missing-service lookups, Remove-Item suppression, and a DNS wrapper that catches .NET exceptions.
What it assumes
Assumes basic PowerShell commands and distinguishes nonterminating errors from .NET exceptions.
What you can do after
Apply it per command to continue, suppress, prompt, ignore, or catch selected failures.
How it connects
Connects nonterminating errors with ErrorActionPreference, terminating exceptions, and try/catch handling.

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 Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.