Tooling for Custom PowerShell Logging
Over the last several articles, we’ve been exploring how to create custom event logs for our PowerShell work. Instead of logging into a text file, write to an event log. The event log will likely be more permanent and easy to search across your organization.
In the last article, I demonstrated Windows PowerShell code you could use to create, manage, and write custom event logs using existing cmdlets. Cmdlets simplify the process. However, these cmdlets do not ship with PowerShell 7. While we can likely still use them via the application compatibility session, I think the better solution is to create tooling specific to PowerShell 7. Even better, these commands should also work natively in PowerShell 7. The command names I’m using reflect PowerShell Core so that I can distinguish them from my Windows PowerShell functions. But feel free to rename them as you wish. Remember, these commands create classic event logs, which is perfectly fine for our purposes.
Testing
First, let’s look at testing if a log exists. This is easily accomplished using the .NET Framework.