PowerShell Logo Small

Write-Error



This is the built-in help made by Microsoft for the command 'Write-Error', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Writes an object to the error stream.

SYNTAX


Write-Error -ErrorRecord <ErrorRecord> [-CategoryActivity <string>] [-CategoryReason <string>] [-CategoryTargetName <string>] [-CategoryTargetTyp
e <string>] [-RecommendedAction <string>] [<CommonParameters>]
Write-Error [-Message] <string> [-Category {NotSpecified | OpenError | CloseError | DeviceError | DeadlockDetected | InvalidArgument | InvalidDat
a | InvalidOperation | InvalidResult | InvalidType | MetadataError | NotImplemented | NotInstalled | ObjectNotFound | OperationStopped | Operatio
nTimeout | SyntaxError | ParserError | PermissionDenied | ResourceBusy | ResourceExists | ResourceUnavailable | ReadError | WriteError | FromStdE
rr | SecurityError}] [-ErrorId <string>] [-TargetObject <Object>] [-CategoryActivity <string>] [-CategoryReason <string>] [-CategoryTargetName <s
tring>] [-CategoryTargetType <string>] [-RecommendedAction <string>] [<CommonParameters>]
Write-Error -Exception <Exception> [-Category {NotSpecified | OpenError | CloseError | DeviceError | DeadlockDetected | InvalidArgument | Invalid
Data | InvalidOperation | InvalidResult | InvalidType | MetadataError | NotImplemented | NotInstalled | ObjectNotFound | OperationStopped | Opera
tionTimeout | SyntaxError | ParserError | PermissionDenied | ResourceBusy | ResourceExists | ResourceUnavailable | ReadError | WriteError | FromS
tdErr | SecurityError}] [-ErrorId <string>] [-Message <string>] [-TargetObject <Object>] [-CategoryActivity <string>] [-CategoryReason <string>]
[-CategoryTargetName <string>] [-CategoryTargetType <string>] [-RecommendedAction <string>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Write-Error cmdlet writes an error to the Windows PowerShell error stream. By default, errors are sent to the host program to be displayed, a
long with output.

You can write an error by submitting an error message string, an ErrorRecord object, or an Exception object. Use the other parameters of Write-E
rror to populate the error record.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113425
Write-Debug
Write-Verbose
Write-Output
Write-Host
Write-Progress
Write-Warning

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-childitem | foreach-object { if ($_.gettype().tostring() -eq "Microsoft.Win32.RegistryKey") {write-error "Out-of-band object" -errorID
B1 -targetobject $_ } else {$_ } }



Description
-----------
This command writes an error when the Get-ChildItem cmdlet returns a Microsoft.Win32.RegistryKey object, such as the objects in the HKLM: or HKCU
drives of the Windows PowerShell Registry provider.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>write-error "Access denied."



Description
-----------
This command writes an "Access denied" error. The command uses the Message parameter to specify the message, but omits the optional Message param
eter name.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>write-error -message "Error: Too many input values." -category InvalidArgument



Description
-----------
This command writes a error and specifies an error category.