Connor Johnson
Connor Johnson

Reputation: 21

Robocopy: adding maxage argument breaks command

So I am simply trying to add the /maxage argument to my robocopy command.

This command works just fine: robocopy $source $destination *.* /e /zb

But once I add /maxage it gives me a Invalid Parameter error robocopy $source $destination *.* /e /zb /maxage:1825

I want it so files older than 5 years are not copied over. Am I missing something? Thank you for your help

I have googled this pretty thoroughly and can't find what I'm missing, but I have to be mistaken on something with this command. Thank you!

Upvotes: 0

Views: 317

Answers (1)

RetiredGeek
RetiredGeek

Reputation: 3168

I've had success using the following template to pass arguments with colons in them.

  $robocopyOptions = @('/e', '/zb', '/maxage:1825')
  $CmdLine = @($source, $destination) + $robocopyOptions           
  & 'robocopy.exe' $CmdLine

Note: I noticed you already had $source & $destination in your code.

Upvotes: 1

Related Questions