The ErrorAction parameter and the ErrorActionPreference variable are used to control what happens when a non-terminating error is written.
ErrorAction parameter requires CmdletBinding.
The ErrorAction parameter is only available if a function declares the CmdletBinding attribute. CmdletBinding automatically added is if the Parameter attribute is used.
The ErrorAction parameter is only available if a function declares the CmdletBinding attribute. CmdletBinding automatically added is if the Parameter attribute is used.
By default, ErrorAction is set to continue. Any non-terminating errors will be displayed, but a script or function will continue to run.
If ErrorAction is set to SilentlyContinue, errors will be added to the $error automatic variable, but the error won't be displayed.
The following function writes a non-terminating error using Write-Error:
function SilentError { [CmdletBinding()] param ( ) Write-Error 'Something went wrong' } SilentError -ErrorAction SilentlyContinue
The error is written...