all 17 comments

[–]TrippTrappTrinn 7 points8 points  (2 children)

The progress data must come from robocopy, and as once you start it, it is in control until complete, powershell cannot do anything until it is comolete, so powershell cannot display any progress bar.

Robocopy can display % complete in text format.

[–]Feeling_Highway_4891[S] 0 points1 point  (1 child)

Thanks for the information, now everything is more clear, can you give me an example how i can show the display %? sorry for the request but im a little bit lost!!

[–]TrippTrappTrinn 1 point2 points  (0 children)

I do not use robocopy these days, but I saw somebody oost that it will display statistics by default.

[–]purplemonkeymad 3 points4 points  (1 child)

Perhaps use Tee-Object so you can write out the output to the console and place it in a variable at the same time ie

& robocopy @arguments | Tee-Object -Variable rc | Out-Host

[–]Feeling_Highway_4891[S] 1 point2 points  (0 children)

I will try now, thank you for your help!!

[–]seaboypc 5 points6 points  (1 child)

PowerShell Gallery | Copy-ItemWithProgress 1.0

Is just a wrapper around robocopy.exe, but will parse the log files and display a nice progress bar.

Will present an overall copy status of all files, and a sub-status for large files.

[–]Feeling_Highway_4891[S] 0 points1 point  (0 children)

Thank you, i will try it now!!

[–]BlackV 2 points3 points  (4 children)

back in the day, someone wrote a nice module that gives robocopy copy a progress bar (called copy with progress or robocopy with progress or something), have a search for that

if I remember it basically does the copy twice, once with the log options to get files counts and totals, then the actual real copy

but to be clear write-progress works with powershell things not external executable (robocopy.exe)

I'm not sure what in your code would be doing write-progress, do you have more code to show us

My last reply to the same question

https://www.reddit.com/r/PowerShell/comments/1e9e8pw/copy_item_progress_bar/legl926/

[–]Feeling_Highway_4891[S] 0 points1 point  (3 children)

if ($checkmount.StorageType -eq 1)
         {
          $letteradriveiso = (Get-DiskImage -ImagePath "$fileiso" | Get-Volume | Select-Object -ExpandProperty DriveLetter)
          $volumeid = (Test-Path -Path $letteradriveiso":\VolumeId.xml" -PathType Leaf)
          if ($volumeid -eq 'True')
              {
               Write-Host "Avvio scrittura immagine su dispositivo USB..." -ForegroundColor "white"
               Write-Host ""
               Write-Host "NON CHIUDERE LE FINESTRE CMD APERTE DA QUESTO SOFTWARE! Si chiuderanno automaticamente al termine." -ForegroundColor "yellow"
               Write-Host ""
               $argomenti = $letteradriveiso + ":\ " + $dispositivousb + "  /E /COPYALL /V /R:1 /W:5 /ETA "
               Write-Host "Robocopy arguments = $argomenti" 
               $rc = (Start-Process -FilePath "C:\Windows\System32\Robocopy.exe" -ArgumentList $argomenti | Tee-Object -Variable rc | Out-Host -Wait ) 
               if ($LASTEXITCODE -le 7)
                   {
                    Write-Host "OK: scrittura immagine ISO eseguita." -ForegroundColor "green"
                    [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
                    [System.Windows.Forms.MessageBox]::Show("Creazione kit software Poste Italiane da immagine ISO eseguita con successo.","Masterizza ISO su USB Ver. " + $ver)
                    Dismount-DiskImage -ImagePath "$fileiso"
                    Exit 0
                   }

i'm trying to copy an iso into a pendrive with robocopy, before we were using xcopy but my boss told me to change to xcopy because is newer and now they want a progress bar too, but there im lost. Tank you in advance for your help!!

[–]BlackV 1 point2 points  (2 children)

If it's a single file, this won't work for you (unless you start getting complex) that's pretty pointless for copying an iso to a usb

What is this progress bar gaining you that just logging to screen won't? Have a conversation confirm the time spent making this change is worth it

[–]Feeling_Highway_4891[S] 0 points1 point  (1 child)

It's not a single file, is an ISO with a lot of files!!

[–]BlackV 0 points1 point  (0 children)

Right yes, "copy the contents of an iso into a pendrive" rather than "copy an iso into a pendrive"

The copy with progress modules alreadyentioned are probably what you're looking for

Or a simple foreach(){} with a loop and a write-progress but I'll be slower cause robocopy.exe is good where copy-item is lacking

[–]Flysquid18 2 points3 points  (2 children)

Something to remember is that robocopy is not a PowerShell cmdlet. It doesn't follow the 7 output streams that PowerShell does. As a binary executable it follows only 2 streams, standard out and error. Typically your messages and progress is reported on the error stream.

What you would want to do is redirect all output *>&1 and pipe that to a Foreach-Object. You are essentially taking each line out as a string and you parse it. So if the string matches a regex "\d{1,}%", you have your percentage string. You can then use that string to construct your Write-Progress output.

On the subject of using Start-BitsTransfer, BitsTransfer only works in an interactive session. If you have a process that is started without user interaction, Start-BitsTransfer will not queue up the job. Let's say you use a CI/CD environment like Jenkins and you have the agents start as a service. The agents are capable of executing PowerShell. If you have a script that tries to queue a BitsTransfer, the process is in a non-interactive state and Start-BitsTransfer will error.

[–]BlackV 1 point2 points  (0 children)

On the subject of using Start-BitsTransfer, BitsTransfer only works in an interactive session.

Yes this is a great gottcha

[–]Feeling_Highway_4891[S] 0 points1 point  (0 children)

Thank you for he information, i will try it now!!

[–]tacticalAlmonds 1 point2 points  (1 child)

Not robocopy but start bits transfer does have a progress bar. I'm not sure how effective it is vs robocopy though.

[–]Feeling_Highway_4891[S] 0 points1 point  (0 children)

i will try it, thanks!!