Powershell Image Conversion script – Part 2: Logging functionality

Standard

One of the important parts of the script is the logging functionality. Because we’re dealing with large amounts of files that are converted it’s good to know what has been done and may have gone wrong.

The following code will write the logfile:

The function will write a line in a logfile. If no logfile exists it will create a logfile with the following name: logfile-yyyymmdd.log. An example of the name could be: logfile-20100922.log
If the file already exists it will not be created, instead it will write to the file. The log in the file would look similar to this:

The function uses the local variable $logfile that has been added as a parameter during execution.
To add the log functionality to the “Convert-Image” do the following:

After the code:

add the following code:

Leave a Reply