Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Cmdlet.WriteError Method (ErrorRecord)

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Reports a nonterminating error to the error pipeline when the cmdlet cannot process a record but can continue to process other records.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public void WriteError(
	ErrorRecord errorRecord
)

Parameters

errorRecord
Type: System.Management.Automation.ErrorRecord

An ErrorRecord object that describes the error condition.

Exception Condition
PipelineStoppedException

The pipeline is stopped. The pipeline was terminated either before the call was made or while the call was in progress. By default, the cmdlet should allow the caller of the processing record method to catch this exception.

InvalidOperationException

The call cannot be completed at this time or cannot be completed from this thread. For more information, see the following Remarks section.

When this method is called, an error record is sent to the error pipeline and control is returned to the cmdlet for more processing. For more information about error reporting and error records, see Windows PowerShell Error Reporting.

This method can be called as many times as necessary, but the calls can be made only from within the cmdlet input processing methods (BeginProcessing, ProcessRecord, and EndProcessing) and only from that thread. If this call is made from outside these methods or from another thread, an InvalidOperationException exception is thrown.

This method should not be used in the following cases:

To write an object to the output pipeline, see WriteObject.

For more information about cmdlets, see Windows PowerShell Cmdlets.

Return to top

Community Additions

Show: