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 ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.