Introduction
The ErrorAction parameter helps you control what happens when a command runs into an error. It lets you decide if the script should stop, continue, or silently ignore errors.
Command -ErrorAction <Action>
Get-Item 'C:\file.txt' -ErrorAction SilentlyContinueGet-Item 'C:\file.txt' -ErrorAction StopGet-Item 'C:\file.txt' -ErrorAction Inquiretry {
Get-Item 'C:\nonexistentfile.txt' -ErrorAction Stop
Write-Output 'File found.'
} catch {
Write-Output 'File not found. Handling error gracefully.'
}-ErrorAction SilentlyContinue parameter do in a PowerShell command?-ErrorAction Stop correctly after the command.Get-Item 'C:\nonexistentfile.txt' -ErrorAction SilentlyContinue; Write-Output 'Done'
Get-Content 'C:\missing.txt' -ErrorAction Stop
Write-Output 'File read successfully'
Pass the test and this pattern moves unknown