0

So I've got the following block of code to robocopy some user data over the network:

$localFiles = "C:\Users\"
$netFiles = "\\netLocation\migration\Users\"

Start-Process "RoboCopy.exe" -NoNewWindow -argumentlist " `"$localFiles\`" `"$netFiles\`" /s /r:1 /w:5 /mt:16"

I have another, similar block of code directly underneath it that copies the same files to an external USB drive. What happens is, the first RoboCopy runs and immediately after the second one runs in unison. What I'd like to do is have the first function wait for RoboCopy to complete before it runs the second function. I have tried the -Wait argument, and that does not appear to work.

Thank you for your time!

MalyG
  • 301
  • 1
  • 6
  • 15
  • 2
    I have no explanation for why `-Wait` doesn't work, but if you want to _wait_ i.e. execute _synchronously_, just invoke robocopy _directly_: `Robocopy.exe $localFiles $netFiles /s /r:1 /w:5 /mt:16` – mklement0 Feb 16 '20 at 21:57
  • 1
    @mklement0 Touche. That does work. – MalyG Feb 16 '20 at 22:32
  • Glad to hear it. I've linked to [another post](https://stackoverflow.com/a/51334633/45375) that provides background information. – mklement0 Feb 16 '20 at 22:45

1 Answers1

1

Per @mklement0:

I have no explanation for why -Wait doesn't work, but if you want to wait i.e. execute synchronously, just invoke robocopy directly: Robocopy.exe $localFiles $netFiles /s /r:1 /w:5 /mt:16 – mklement0

Resolved

MalyG
  • 301
  • 1
  • 6
  • 15