Write-EventLog
Syntax
Default (Default)
Write-EventLog
[-LogName] <String>
[-Source] <String>
[[-EntryType] <EventLogEntryType>]
[-Category <Int16>]
[-EventId] <Int32>
[-Message] <String>
[-RawData <Byte[]>]
[-ComputerName <String>]
[<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.
Examples
Example 1
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
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.
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.
Parameter properties
| Type: | Int16 |
| Default value: | 1 |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-ComputerName
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.
Parameter properties
| Type: | String |
| Default value: | Local computer |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | CN |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-EntryType
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 EventLogEntryType Enumeration in the MSDN library.
Parameter properties
| Type: | EventLogEntryType |
| Default value: | Information |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | ET |
Parameter sets
(All)
| Position: | 4 |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-EventId
Specifies the event identifier. This parameter is required.
Parameter properties
| Type: | Int32 |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | ID, EID |
Parameter sets
(All)
| Position: | 3 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-LogName
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.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | LN |
Parameter sets
(All)
| Position: | 1 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Message
Specifies the event message. This parameter is required.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | MSG |
Parameter sets
(All)
| Position: | 5 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-RawData
Specifies the binary data that is associated with the event, in bytes.
Parameter properties
| Type: | Byte[] |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | RD |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Source
Specifies the event source, which is typically the name of the application that is writing the event to the log.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | SRC |
Parameter sets
(All)
| Position: | 2 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
None
You cannot pipe input to this cmdlet.
Outputs
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.