Scripting with Integrated Logging
Let’s continue working with custom event logs and PowerShell. This could be a useful logging mechanism that is persistent and searchable. If you’ve ever needed an audit process for your PowerShell scripts and functions, this is a great place to start. Yes, it will take extra work up front and planning, but I bet you’ll be happy with the results.
In the previous article, I demonstrated various techniques for working with custom event logs and sources. We can use cmdlets in Windows PowerShell, which makes life a little easier. PowerShell 7 might be able to use the same cmdlets, but since the commands are not included with PowerShell 7, I’d rather have tooling specific to PowerShell 7. I’ll get to that later. For now, let’s look at ways to abstract the process with the Windows PowerShell cmdlets.
Windows PowerShell
I want to create an event log called PSCompany, which means I must ensure it doesn’t already exist. So, I wrote a simple test function.