-ErrorAction is a PowerShell common parameter for choosing how a command responds to non-terminating errors. Its most important automation use is making a command failure visible to structured error handling instead of letting execution continue as though the command succeeded. section 6.1.1
Use -ErrorAction Stop inside a try block when a failed command must transfer control to catch. Stop turns non-terminating errors into terminating errors, so later statements in the try block are skipped and the caught error is available in $_. A finally block can then log or clean up regardless of success or failure. section 3.3.5 section 6.1.1
Choose the response based on what a failed step means to the remaining work:
- Use Stop when a failure would invalidate later steps, such as a required setup operation whose failure would cause subsequent work to fail. section 6.1.1
- Use non-terminating handling when later items can still be processed after one failure, then review and address the recorded failures afterward. section 6.1.1
- Avoid treating SilentlyContinue as proof of an expected condition. Suppressing a Get-Service error can hide either a missing service or an unrelated problem such as insufficient permissions. section 6.1
Handle a missing service deliberately
A service-management script can call Get-Service -Name xyz -ErrorAction Stop in try. Catch then examines $_.FullyQualifiedErrorId: an expected missing-service error may be recorded and skipped, while an unexpected error can be sent to Write-Error or thrown. This preserves processing of other services without concealing permission or operational failures. section 6.1.1 section 6.1
Action scripts that run independently need their own error handling and logging. Place the operational function call in try, set a success message only after it completes, set an error message in catch, and write the result in finally. This leaves an audit trail whether a file operation succeeds or fails. section 3.3.5
try{
Get-Service -Name xyz -ErrorAction Stop
}
catch{
$_
}
This minimal pattern shows why try/catch alone is insufficient for a non-terminating Get-Service error and where -ErrorAction Stop belongs. section 6.1.1


