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

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mike Mike 12 months ago.

  • Author
  • #31331
    Profile photo of Mike

    OK so here is the short and sweet...

    $d=get-date -Uformat %Y%m%d
    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"?

  • #31333
    Profile photo of Tim Curwick
    Tim Curwick


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


  • #31334
    Profile photo of Mike

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

You must be logged in to reply to this topic.