October 2017
Intermediate to advanced
440 pages
11h 47m
English
The Write-Error command can be used to write non-terminating error messages.
The Write-Error command can be used with nothing more than a message:
Write-Error 'Message'
Or it might include additional information, such as a category and error ID to aid diagnosis by someone using the script:
Write-Error -Message 'Message' -Category 'InvalidOperation' -ErrorId 'UniqueID'
The following example shows a non-terminating error raised while running a loop:
function Test-Error {
for ($i = 0; $i -lt 5; $i++) {
Write-Error -Message "Iteration: $i"
} }
Test-Error
The error will be displayed five times without stopping execution.
The CmdletBinding attribute adds support for common parameters, including ErrorAction. ErrorAction can be used ...
Read now
Unlock full access