-1

Trying to use Powershell to backup some large dir -newbie

I can't make this line to work

"C:\Robocopy\RoboCopy.exe" $source $destination "/E /R:10 /W:5 /V /ETA"

Robocopy at best (depending on the " i put here or there..) is executed but it's its GUI that is launched (and nothing more is done).

There's no issue with the $dest and $source (I manage to log into a txt file and his is working)

Thank you

user1011212
  • 39
  • 1
  • 8
  • Do not quote the parameters starting at `/E`. Just put them after the `$destination` variable without quotes. – Bill_Stewart Oct 05 '17 at 14:57
  • thank you but still not working.. – user1011212 Oct 06 '17 at 07:08
  • Quoting all the parameters the way you were doing it _definitely_ won't work, because that means you are passing that entire quoted string as a _single_ parameter. When you say "still not working," you need to be specific about _how_ it is not working. Open a PowerShell prompt and type the command, and observe the behavior. – Bill_Stewart Oct 06 '17 at 14:02
  • Also, to run a quoted executable name in PowerShell, you must prefix the quoted string command with the `&` (call) operator. – Bill_Stewart Oct 06 '17 at 14:03

1 Answers1

0

Use this:

& "C:\Robocopy\RoboCopy.exe" $source $destination /E /R:10 /W:5 /V /ETA

The & (call) operator is required if you want PowerShell to run a quoted string as a command.

In this specific case, the quotes are not needed because the executable's path and filename don't contain spaces, so you can just write this instead:

C:\Robocopy\RoboCopy.exe $source $destination /E /R:10 /W:5 /V /ETA

But is robocopy.exe really sitting in C:\Robocopy? Do you have that directory name? Robocopy.exe is a tool that comes with the OS and should already be in the path. Why not just this?

robocopy $source $destination /E /R:10 /W:5 /V /ETA
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62