Using get-date -Uformat %Y%m%d for log file name

OK so here is the short and sweet…

$d=get-date -Uformat %Y%m%d
$folder=“TestFolder”
robocopy.exe C:$folder D:$folder /LOG:Log_$folder_$d.txt

For some reason the file name of the log ends up being “Log_20151026.txt”. The folder name does not get included in the log. If I remove the $d (/LOG:Log_$folder.txt). The log will be “Log_TestFolder”. What am I missing here? What needs to be changed so that the log file will be “Log_TestFolder_20151026.txt”?

Mike,

PowerShell is assuming the underscore is part of the name of the variable. Try this:

“/LOG:Log_$($Folder)_$d.txt”

Thanks Tim for the prompt reply! That is exactly what I was looking for. :slight_smile: