Export (0) Print
Expand All

Write-EventLog

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Write-EventLog

Writes an event to an event log.

Syntax

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




Detailed 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 Windows, use Get-WinEvent.

Parameters

-Category<Int16>

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.


Aliases

none

Required?

false

Position?

named

Default Value

1

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ComputerName<String>

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

Type the NetBIOS name, an Internet Protocol (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 Get-EventLog even if your computer is not configured to run remote commands.


Aliases

none

Required?

false

Position?

named

Default Value

Local computer

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-EntryType<EventLogEntryType>

Specifies the entry type of the event. Valid values are Error, Warning, Information, SuccessAudit, and FailureAudit. The default value is Information.

For a description of the values, see System.Diagnostics.EventLogEntryType in the MSDN library at http://go.microsoft.com/fwlink/?LinkId=143599.


Aliases

none

Required?

false

Position?

4

Default Value

Information

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-EventId<Int32>

Specifies the event identifier. This parameter is required.


Aliases

none

Required?

true

Position?

3

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-LogName<String>

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


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Message<String>

Specifies the event message. This parameter is required.


Aliases

none

Required?

true

Position?

5

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RawData<Byte[]>

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


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Source<String>

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


Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You cannot pipe input to this cmdlet.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.Diagnostics.EventLogEntry

    Write-EventLog returns objects that represents the events in the logs.


Notes

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

Examples

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

This command writes an event from the MyApp source 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

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

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


PS C:\> write-eventlog -computername Server01 -logname Application -source MyApp -eventID 3001 -message "MyApp added a user-requested feature to the display."

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft