0

I have successfully incorporated Write-Progress into my scripts. When my scripts get to any portion where RoboCopy is used Write-Progress disappears and reappears when RoboCopy is complete:

Write-Progress -Id 1 -Activity $arg2 -PercentComplete $i -Status $arg1
RoboCopy C:\source C:\destination /MIR

I have considered using Start-Process to run Write-Progress but have had limited success. Any help would be gladly appreciated.

Vippy
  • 1,356
  • 3
  • 20
  • 30

2 Answers2

1

I was able to answer my own question. Here is the solution by using Start-Job:

Write-Progress -Id 1 -Activity $arg2 -PercentComplete $i -Status $arg1
Start-Job { RoboCopy C:\source C:\destination /MIR LOG+:C:\log.txt } > $null
cat C:\log.txt

So let me explain. Start-Job creates a background job and redirects it's own output to the bit-bucket. Since it's a background job, I'm immediately returned to run more stuff, like cat which spills all the contents of RoboCopy's log file. In the end, it works as it should to begin with. YAY!

Vippy
  • 1,356
  • 3
  • 20
  • 30
0

I suspect Robocopy takes over the console display buffer to display progress. Try using the robocopy options /NP /NJH /NJS. You may also need to add /NS /NC /NFL /NDL.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • I'll experiment using different options. Thanks again Keith! – Vippy Sep 07 '12 at 21:38
  • Ok, this works; however all output from RoboCopy is suppressed. I want my cake and eat it too. :) – Vippy Sep 07 '12 at 22:24
  • Try removing some of the /N* options. It would be useful to figure out which one (or ones) mess up PowerShell's Write-Progress display. – Keith Hill Sep 07 '12 at 22:26
  • I tried all sorts of combinations of the /N* options. Didn't work, however I became more familiar with RoboCopy and that is a good thing! Thanks again. – Vippy Sep 10 '12 at 14:55