question

MartinThomas-3019 avatar image
0 Votes"
MartinThomas-3019 asked RichMatheisen-8856 answered

How to write Windows event logs in PowerShell 7+

Hi,

I'm currently working on rewriting a number of old scripts and I'm taking the opportunity to write them under PS7. I've come to a hard stop when I could not find how to migrate the old logging code that is writing to the event logs.

As *-EventLog cmdlets who rely on unsupported APIs are now deprecated. I'm looking into using newer and supported methods to write to the event log.

Unfortunately, I've been unable to find a relatively direct replacement of a simple usage such as this:

"Write-EventLog -LogName $LogName -Source $Source -EntryType $EntryType -EventId $EventID -Message $Message"

Can anyone share a source of information on "writing event logs for dummies"? :)

Thanks!

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

This might point you in the right direction:
how-to-write-a-custom-event-log-by-an-already-existing-provider-with-powershell

But I don't think that the New-WinEvent is what you're looking for. The description for that cmdlet says:

The New-WinEvent cmdlet creates an Event Tracing for Windows (ETW) event for an event provider. You can use this cmdlet to add events to ETW channels from PowerShell.

PowerShell 7 is a cross-platform version of PowerShell. There are still many things it doesn't do that version 5 does, and things it does differently to version 5. Unless you have a need (not just curiosity) to use version 7 I'd stick with version 5.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.