Simple log function

I needed a way to log the console output in PowerShell, which would then allow me to email this (a quick and easy way for me to check that my automated scripts were working correctly).

The following function does just that, sort of.

Instead of capturing everything that is written to the console, text is passed to the Log function which then updates the $Log string before returning the same text to ensure it is written to the console.

Line breaks are automatically added to the string.

The code below shows how to use the Log function.

It’s important to remember that this function will not capture any errors thrown by your script. So, you’ll need to make sure you handle errors correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *