Send-ToEventLog



Summary

Sends a message to an event log

Syntax

Send-ToEventLog [[-source] <String>] [[-id] <Int32>] [-message] <Object> [[-severity] {error | warning | informational | success_audit | failure_audit}] [[-category] <Int16>] [[-logname] <String>] [[-rawdata] <Byte[]>] [[-target] <String>] [[-PassThru]] [<CommonParameters>]

Description

This command sends a message to an event log.

The source should be initialized with the Register-EventLogSink command to register the source name prior to using this command.

Parameters

Name Argument Description
source <String> Specifies the event log source that will be used when logging. This source should be registered via the Register-EventLogSink command.

The source can also be specified via the HPSINK_EVENTLOG_MESSAGE_SOURCE environment variable.
id <Int32> Specifies the event id that will be registered under the 'Event ID' column in the event log. Default value is 0.
message <Object> Specifies the message to log. This parameter is required.
severity <eventlog_severity_t> Specifies the severity of the message. If not specified, the severity is set as 'Information'.
category <Int16> Specifies the category of the message. The category shows up under the 'Task Category' column. If not specified, it is 'General', unless environment variable HPSINK_EVENTLOG_MESSAGE_CATEGORY is defined.
logname <String> Specifies the log in which to log (e.g. Application, System, etc). If not specified, it will log to Application, unless environment variable HPSINK_EVENTLOG_MESSAGE_LOG is defined.
rawdata <Byte[]> Specifies any raw data to add to the log entry
target <String> Specifies the target computer on which to perform this operation. Local computer is assumed if not specified, unless environment variable HPSINK_EVENTLOG_MESSAGE_TARGET is defined.

Important: the user identity running the PowerShell script must have permissions to write to the remote event log.
PassThru If specified, this command sends the message to the pipeline upon completion and any error in the command is non-terminating.

Notes

This command reads the following environment variables for setting defaults.

  • HPSINK_EVENTLOG_MESSAGE_SOURCE: override default source name
  • HPSINK_EVENTLOG_MESSAGE_CATEGORY: override default category id
  • HPSINK_EVENTLOG_MESSAGE_LOG: override default message log name
  • HPSINK_EVENTLOG_MESSAGE_TARGET: override event log server name

Defaults can be configured via the environment. This affects all related commands. For example, when applying them to eventlog-related commands, all eventlog-related commands are affected.

In the following example, the HPSINK_EVENTLOG_MESSAGE_TARGET and HPSINK_EVENTLOG_MESSAGE_SOURCE variables affect both the Register-EventLogSink and Send-ToEventLog commands.

$ENV:HPSINK_EVENTLOG_MESSAGE_TARGET="remotesyslog.mycompany.com"
$ENV:HPSINK_EVENTLOG_MESSAGE_SOURCE="mysource"
Register-EventLogSink
"hello" | Send-ToEventLog

Examples


PS C:\> "hello" | Send-ToEventLog

See also