17.7. The write-error Cmdlet
The write-error cmdlet writes an error object and passes it to the pipeline. In addition to supporting the common parameters, the write-error cmdlet supports the following parameters:
Message — Text that describes the error. Can be used in place of the Exception and ErrorRecord parameters. A required parameter.
Category that — The category of error that the error is associated with. An optional parameter.
ErrorId — The error ID associated with the error. An optional parameter.
TargetObject — The object associated with the error. An optional parameter.
RecommendedAction — The action recommended in response to the error. An optional parameter.
CategoryActivity — A description of the activity that overrides the ErrorCategoryInfo default. An optional parameter.
CategoryReason — A text description of the reason to override the ErrorCategoryInfo default. An optional parameter.
CategoryTargetName — The Target Name to override the ErrorCategoryInfo default. An optional parameter.
CategoryTargetType — The Target Type to override the ErrorCategoryInfo default. An optional parameter.
Exception — The type of the error's exception. If used instead of the Message and ErrorRecord parameters, it is a positional parameter in position 1.
ErrorRecord — An error record containing information about the error. If used instead of the Message and Exception parameters it is a positional parameter in position 1.
The permitted values of the Category parameter are listed here:
NotSpecified ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access