RadFox
RadFox

Reputation: 419

Robotcopy with log + report date

I am running a Robocopy command and I am now getting a strange error where it once worked. I did look at several other StackExchange articles, but they do not deal with what I am dealing with.

  1. Talks about C# code
  2. Command for Robocopy to log created date
  3. Create File with current Date in Filename + Robocopy logging
  4. Robocopy: ERROR : Invalid Parameter #4

I created some code that adds a date to the end of the robocopy log.

$ReportDate = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")
$RoboCopyLog = New-Item -itemType File -Path C:\Results -Name $("RoboCopyLog_" + $ReportDate + ".txt")

I have logs where this was working, but after some Windows updates and not touching it for a few weeks, I am now getting this error.

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                            

-------------------------------------------------------------------------------

  Started : Tuesday, March 21, 2017 7:24:56 AM
   Source - C:\MyTests\
     Dest - C:\NewTests\

    Files : 
  Options : /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : "/L:C:\Results\RoboCopyLog_21-03-2017-07-24-56.t
xt"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /?


****  /MIR can DELETE files as well as copy them !

The command I am using to create my robocopy job is as follows:

$RoboCopy2 = Start-Job {
$Results = "C:\Results"
$Source = "C:\MyTests"
$Destination = "C:\NewTests"
$ReportDate = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")
$RoboCopyLog = New-Item -itemType File -Path C:\Results -Name $("RoboCopyLog_" + $ReportDate + ".txt")


Robocopy $Source $Destination /E /L:$RoboCopyLog

}
Wait-Job $RoboCopy2
Receive-Job $RoboCopy2

Upvotes: 1

Views: 3680

Answers (1)

Will Webb
Will Webb

Reputation: 805

As Ansgar Wiechers mentioned, your problem is when calling your /L:RoboCopyLog.

If you see the documentation for Robocopy here you will find that:

/l Specifies that files are to be listed only (and not copied, deleted, or time stamped).

Whereas what you are requiring is either of these depending if you want to append or not:

/log:<LogFile> Writes the status output to the log file (overwrites the existing log file).

/log+:<LogFile> Writes the status output to the log file (appends the output to the existing log file).

Upvotes: 1

Related Questions