Home > Net >  COPY /Z equivalent in PowerShell
COPY /Z equivalent in PowerShell

Time:10-19

I'm trying to get used to using PowerShell whenever I'm tempted to reach for the familiar CMD command line that I've known and come to not-quite-love over a couple of decades. I'm starting to internalize Copy-Item, but one of the things I really miss when copying large files is the /Z argument. If you're not familiar with the /Z argument, it adds a quick progress indicator (see below). For small files, it's completely unnecessary, but it is a sanity saver when copying huge files, especially over a slow network.

COPY /Z

Is there anything comparable to COPY /Z in PowerShell that doesn't involve lots of code? I'm hoping for something as easy an memorable as a simple argument or maybe a pipable cmdlet along the lines of: Copy-Item -Path "C:\Source\File.exe" -Destination "C:\Destination\" | Show-Progress

Am I out of luck, or does something like this already exist?

CodePudding user response:

While some PowerShell cmdlets support progress displays, Copy-Item does not.

  • For those that do support progress displays, such as Invoke-WebRequest, the logic is usually reversed. Progress is shown by default, and must be silenced on demand, with $ProgressPreference = 'SilentlyContinue'

  • While PowerShell offers the Write-Progress cmdlet for creating your own progress displays, this won't help you here, as you cannot track the internal progress of a single object being processed by another command.

However, you can simply call cmd.exes internal copy command from PowerShell, via cmd /c:

cmd /c copy /z C:\Source\File.exe C:\Destination\

Note:

  • As Jeroen Mostert points out, consider using robocopy.exe instead (which you can equally call from PowerShell) - see his comment on the question for details.
  • Related