Integrated PowerShell Logging
PowerShell on its own doesn’t have logging capabilities other than Start-Transcript
. There’s no common parameter you can add to a function to log script or command activity. You have to create your own logging mechanism, and I’m sure many of you have. I’ve created a few of my own over the years, but another option you might not have considered is using an actual event log.
Classic vs. Application
In order to take advantage of event logs with your PowerShell scripts, you will need to rely on classic event logs. Based on my experience and research, creating event logs like PowerShellCore/Operational requires developer tools and skills outside our scope. While you could probably write to one of the existing logs, I’d advise against it. These logs are designed for specific purposes and applications. We can get the job done with traditional or classic event logs. Although, as I’ll cover later, the cmdlets we want to use are limited to Windows PowerShell 5.1. The commands aren’t part of PowerShell 7, although you might be able to access them via the compatibility remoting session. For now, assume everything will require Windows PowerShell 5.1.