If you don’t know what your code is doing, how are you supposed to troubleshoot it? How are you supposed to optimize it? To show what it changed in an environment? Log everything!
Especially on long-running scripts or scripts executed in production, you must bake logging routines into your code. It’s not only helpful to monitor activity when things go well, it’s especially helpful when problems arise that need investigation.
In this chapter, you’ll learn some tips on how to best implement logging in your PowerShell scripts.
Use a Logging Function
Logging to a text file is an extremely common ...