PowerShell Write-EventLog Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed New-EventLog cmdlet in PowerShell.
https://cloudaffaire.com/powershell-new-eventlog-cmdlet/
In this blog post, we will discuss Write-EventLog cmdlet in PowerShell. You can use Write-EventLog cmdlet to write new events to a windows event log. You need to have administrative access in order to write an event to an event log. In order to write to the event log, the event log must exist with a proper source registered. You can use Write-EventLog cmdlet to write events into a local or remote computer event log.
Write-EventLog Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 |
## Write-EventLog ## [-LogName] ## [-Source] ## [[-EntryType] ## [-Category ## [-EventId] ## [-Message] ## [-RawData ## [-ComputerName ## [ |
Write-EventLog Cmdlet Argument List:
- –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.
- –ComputerName: Specifies a remote computer. The default is the local computer.
- –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.
- –EventId: Specifies the event identifier. This parameter is required. The maximum value for the EventId parameter is 65535.
- –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. This parameter is required.
- –Message: Specifies the event message. This parameter is required.
- –RawData: Specifies the binary data that is associated with the event, in bytes.
- –Source: Specifies the event source, which is typically the name of the application that is writing the event to the log.
PowerShell Write-EventLog Cmdlet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
########################################## ## PowerShell | Cmdlet | Write-EventLog ## ########################################## ## PowerShell Latest Version (5) ## run PowerShell as admin ## create a sample file New-Item -ItemType File -Path C:\myfile.dll -Value "hello world" ## create a new event log New-EventLog -source MySource -LogName MyLog -MessageResourceFile C:\myfile.dll ## write an new event into an event log Write-EventLog -LogName "MyLog" -Source "MySource" -EventID 1000 ` -EntryType Information -Message "Hello World" ## get the event from the event log Get-EventLog -LogName "MyLog" ## clear the event log Clear-EventLog -LogName "MyLog" ## delete the event log Remove-EventLog -LogName "MyLog" Remove-Item -Path C:\myfile.dll |
Hope you have enjoyed this article. In the next blog post, we will discuss Limit-EventLog CmdLet in PowerShell.
To Set more details on PowerShell, kindly follow below official documentation