Reputation: 1422
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.
Upvotes: 0
Views: 2747
Reputation: 1422
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!
Upvotes: 1
Reputation: 201922
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
.
Upvotes: 0