Write-Error

 

SYNOPSIS

Writes an object to the error pipeline.

 

SYNTAX

Write-Error [-message] <string> [-category {<NotSpecified> | <OpenError> | <CloseError> | <DeviceError> | <DeadlockDetected> | <InvalidArgument> | <InvalidData> | <InvalidOperation> | <InvalidResult> | <InvalidType> | <MetadataError> | <NotImplemented> | <NotInstalled> | <ObjectNotFound> | <OperationStopped> | <OperationTimeout> | <SyntaxError> | <ParserError> | <PermissionDenied> | <ResourceBusy> | <ResourceExists> | <ResourceUnavailable> | <ReadError> | <WriteError> | <FromStdErr> | <SecurityError>}] [-errorId <string>] [-targetObject <Object>] [-recommendedAction <string>] [-categoryActivity <string>] [-categoryReason <string>] [-categoryTargetName <string>] [-categoryTargetType <string>] [<CommonParameters>]

 

Write-Error [-message] <string> -exception <Exception> [-category {<NotSpecified> | <OpenError> | <CloseError> | <DeviceError> | <DeadlockDetected> | <InvalidArgument> | <InvalidData> | <InvalidOperation> | <InvalidResult> | <InvalidType> | <MetadataError> | <NotImplemented> | <NotInstalled> | <ObjectNotFound> | <OperationStopped> | <OperationTimeout> | <SyntaxError> | <ParserError> | <PermissionDenied> | <ResourceBusy> | <ResourceExists> | <ResourceUnavailable> | <ReadError> | <WriteError> | <FromStdErr> | <SecurityError>}] [-errorId <string>] [-targetObject <Object>] [-recommendedAction <string>] [-categoryActivity <string>] [-categoryReason <string>] [-categoryTargetName <string>] [-categoryTargetType <string>] [<CommonParameters>]

 

Write-Error -errorRecord <ErrorRecord> [-recommendedAction <string>] [-categoryActivity <string>] [-categoryReason <string>] [-categoryTargetName <string>] [-categoryTargetType <string>] [<CommonParameters>]

 

DETAILED DESCRIPTION

Writes an object to the error pipeline. Lets you write error messages along with other information such as an id, object data, and suggested actions.

 

PARAMETERS

 

-message <string>

Specifies the message text of the error.

 

Required?

true

Position?

1

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-category <ErrorCategory>

Specifies the category of the error.

 

The following lists the acceptable values for this parameter:

 

·          NotSpecified

·          OpenError

·          CloseError

·          DeviceError

·          DeadlockDetected

·          InvalidArgument

·          InvalidData

·          InvalidOperation

·          InvalidResult

·          InvalidType

·          MetadataError

·          NotImplemented

·          NotInstalled

·          ObjectNotFound

·          OperationStopped

·          OperationTimeout

·          SyntaxError

·          ParserError

·          PermissionDenied

·          ResourceBusy

·          ResourceExists

·          ResourceUnavailable

·          ReadError

·          WriteError

·          FromStdErr

·          SecurityError

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-errorId <string>

Specifies an ID to associate with the error. It should be a string unique to the error.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-targetObject <Object>

Specifies the object with which the error is associated.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-recommendedAction <string>

Describes the recommended response to the error.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-categoryActivity <string>

Describes the action which overrides the ErrorCategoryInfo default.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-categoryReason <string>

Describes the reason the ErrorCategoryInfo default is overridden.

 

Required?

false

Position?

named

Default value

From ErrorCategoryInfo

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-categoryTargetName <string>

Specifies the target name of the ErrorCategoryInfo override.

 

Required?

false

Position?

named

Default value

From ErrorCategoryInfo

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-categoryTargetType <string>

Specifies the target type to override the ErrorCategoryInfo default.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-exception <Exception>

Specifies the exception type of the error. This parameter can be used in place of Message and ErrorRecord, in which case it should appear as the first parameter of the parameter set.

 

Required?

true

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-errorRecord <ErrorRecord>

Specifies an error record describing details about the error. This parameter can be used in place of the Exception and Message parameters, in which case it is the first parameter of the parameter set.

 

Required?

true

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Any

 

RETURN TYPE

Error object

 

NOTES

 

For more information, type "Get-Help Write-Error -detailed". For technical information, type "Get-Help Write-Error -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

get-childitem | foreach-object { if ($_.gettype().tostring() -eq "Microsoft.Win32.RegistryKey")

{write-error "Out-of-band object" -errorID B1 -targetobject $_ } else {$_ } }

 

This command writes an object to the error pipeline if the Get-ChildItem cmdlet returns an object of type Microsoft.Win32.Registry, which it will do if the command is run within the namespace of the Registry provider.

 

RELATED LINKS

Write-Debug

Write-Verbose

Write-Output

Write-Host

Write-Progress

Write-Warning