time stamping log files in powershell

I thought when I previously mentioned PowerShell’s get-date, that I covered how to make dated log files. After seeing this article from TechTarget, I checked and saw I missed it. Here’s how I do it.

new-item -type file -name “$(get-date -uformat ‘%Y%m%d%H%M%S’)-log.log”

This results in a file named: 20080125163647-log.log. Specifying a -path will create the file somewhere else. The switches in the -uformat can be further examined with “get-help get-date -full.”