I want to show a progress-bar while copying items from one folder to another using copy-item.
The following script does not work as intended. I've tried alot of things, but nothing seems to work.
The documentation of progress-bar does not show a good example of copying items.
The progress bar shows 100% and starts to copy everything afterwards.
If i move the copy-item into the foreach loop, it loops and starts to copy again in another subfolder of the destination. After the second copy it continues to loop, but fails.
Any suggestions how to make a progress-bar while copying items?
if (Test-Path -path C:\Source\)
Remove-Item C:\Source -recurse
$sourcePath = 'C:\Source'
$destinationPath = 'C:\Drivers'
$file = Get-ChildItem -Path $sourcePath
Foreach ($filecount in $file)
Write-Progress -activity "Copying drivers" -Status "Progress:" -percentcomplete (($i/$file.count)*100)
Copy-Item $sourcePath $destinationPath -recurse
Copy-Item C:\Source C:\Drivers -recurse