Write-​Event​Log

Writes an event to an event log.

Syntax

Write-EventLog
     [-LogName] <String>
     [-Source] <String>
     [-EventId] <Int32>
     [[-EntryType] <EventLogEntryType>]
     [-Message] <String>
     [-Category <Int16>]
     [-ComputerName <String>]
     [-RawData <Byte[]>]
     [<CommonParameters>]

Description

The Write-EventLog cmdlet writes an event to an event log.

To write an event to an event log, the event log must exist on the computer and the source must be registered for the event log.

The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of the Windows operating system, use the Get-WinEvent cmdlet.

Examples

Example 1: Write an event to the Application event log

PS C:\> Write-EventLog -LogName "Application" -Source "MyApp" -EventID 3001 -EntryType Information -Message "MyApp added a user-requested feature to the display." -Category 1 -RawData 10,20

This command writes an event from the MyApp source to the Application event log.

Example 2: Write an event to the Application event log of a remote computer

PS C:\> Write-EventLog -ComputerName "Server01" -LogName Application -Source "MyApp" -EventID 3001 -Message "MyApp added a user-requested feature to the display."

This command writes an event from the MyApp source to the Application event log on the Server01 remote computer.

Required Parameters

-EventId

Specifies the event identifier. This parameter is required. The maximum value for the EventId parameter is 65535.

Type:Int32
Aliases:ID, EID
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-LogName

Specifies the name of the log to which the event is written. Enter the log name. The log name is the value of the Log property, not the LogDisplayName. Wildcard characters are not permitted. This parameter is required.

Type:String
Aliases:LN
Position:0
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Message

Specifies the event message. This parameter is required.

Type:String
Aliases:MSG
Position:4
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Source

Specifies the event source, which is typically the name of the application that is writing the event to the log.

Type:String
Aliases:SRC
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Optional Parameters

-Category

Specifies a task category for the event. Enter an integer that is associated with the strings in the category message file for the event log.

Type:Int16
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ComputerName

Specifies a remote computer. The default is the local computer.

Type the NetBIOS name, an IP address, or a fully qualified domain name of a remote computer.

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of the Get-EventLog cmdlet even if your computer is not configured to run remote commands.

Type:String
Aliases:CN
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EntryType

Specifies the entry type of the event. The acceptable values for this parameter are: Error, Warning, Information, SuccessAudit, and FailureAudit. The default value is Information.

For a description of the values, see System.Diagnostics.EventLogEntryTypehttp://go.microsoft.com/fwlink/?LinkId=143599 (http://go.microsoft.com/fwlink/?LinkId=143599) in the Microsoft Developer Network (MSDN) library.

Type:EventLogEntryType
Aliases:ET
Parameter Sets:Error, Information, FailureAudit, SuccessAudit, Warning
Position:3
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-RawData

Specifies the binary data that is associated with the event, in bytes.

Type:Byte[]
Aliases:RD
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

You cannot pipe input to this cmdlet.

Outputs

System.Diagnostics.EventLogEntry

This cmdlet returns objects that represents the events in the logs.

Notes

  • To use Write-EventLog, start Windows PowerShell by using the Run as administrator option.

*