PowerShell Logging

While I've been writing scripts and other PowerShell code, one of the things that has helped me greatly is the idea of documentation and logging. I can't emphasize this enough.

I leverage Write-Debug and Write-Verbose in almost every script I write. And I'm using Start-Transcript more now as well. Not only does it document everything, but when I'm troubleshooting scripts I have a nice flow of information to guide my line of thinking. For me, it just seems complete. And that Start-Transcript cmdlet just dumps everything into a nice text file for me to reference in production if I ever need to. It's just so complete.

Then the #PSBlogWeek happened. It actually occurred in December 2015 but it was republished in the monthly PowerShell TechLetter (sign-up here). And the topic for the blog week was logging. Two of the posts were directed towards the Windows Event log system. I realized there is a better logging system already in place, I should use this instead.

So I want to call out the two specific blog posts -

And again, do consider signing up for the PowerShell newsletter. Don Jones and team put some amazing content into it and it's well worth your time.