I'm interested in a PowerShell script that copies a large amount of files from a server daily and I'm interested in implementing a in-console progress bar like
File copy status - XX% complete.
where XX%
updates on the same line instead of newline after newline. I've decided to go with RoboCopy for now. I've currently got
ROBOCOPY 'C:\Users\JMondy\Desktop\Sample1' 'C:\Users\JMondy\Desktop\Sample2' . /E /IS /NFL /NJH
What is the next step?
Best Answer
I wrote a PowerShell function called
Copy-WithProgress
that will achieve what you are after. Since you specifically stated that you were using robocopy, I built a PowerShell function that encapsulates the robocopy functionality (at least, parts of it).Allow me to show you how it works. I've also recorded and posted a YouTube video demonstrating how the function is designed to work, and invoking a test run.
The function is divided into regions:
There are several parameters on the function.
At the bottom of the script (after the function definition), is a complete example of how to call it. It should work on your computer, since everything is variable-ized. There are five steps:
Copy-WithProgress
functionCopy-WithProgress
function again, and validate only changes are replicatedHere is a screenshot of what the function's output looks like. You can leave off the
-Verbose
parameter, if you do not want all of the debugging information. APSCustomObject
is returned, by the function, which tells you:Here is a screenshot of the PowerShell Progress Bar in the PowerShell ISE, and the PowerShell Console Host.
Here is the code: