When you’re creating a PowerShell script that is intended to be run as a scheduled task or be invoked by another process, i.e. the script will not run interactively, you won’t be able to use the console to display messages from the running script.

How do we deal with this? One way is to output the messages to a log file.

With this in mind, I have created a simple PowerShell function that I can reuse in my different scripts.