PowerShell uses xcopy, robocopy or copy-item

The reason for switching from batch files to powershell scripts is to improve process error checking. Does the cmdlet have any advantages in this regard?

If a batch file already exists that uses xcopy to copy files by file name separately, is there any advantage to converting syntax to instance element?

What are the advantages of using robocopy, xcopy and copy-item (compared to each other)? For example, robocopy has the advantage of working with a large number of small files over a reliable network. If this script has to run simultaneously on hundreds of computers in order to copy hundreds of files to each of them, will this affect the decision? Should the solution focus primarily on file permissions?

+8
powershell xcopy copy-item
source share
1 answer

The main advantage is that you can send Copy-Item objects through a pipe instead of strings or files. So you can do:

 Get-ChildItem '\\fileserver\photos\*.jpeg' -File | ` Where-Object { ($_.LastAccessTime -ge (Get-Date).AddDays(-1)) -and ($_.Length -le 500000) } | ` Copy-Item -Destination '\\webserver\photos\' 

Some kind of bad example (you can do it with Copy-Item -Filter ), but it is easy to find on the fly. This is quite common when working with files, in order to eventually get the pipeline from Get-ChildItem , and I personally often do this simply because of the -Recurse -Include with Remove-Item .

You also get PowerShell error captures, special options like -Passthru , -WhatIf , -UseTransaction and all common options. Copy-Item -Recurse can replicate some copying capabilities of xcopy instances, but these are pretty bare bones.

Now, if you need to support ACLs, property rights, audits, etc., then xcopy or robocopy will probably be much simpler because this functionality is built-in. I'm not sure how Copy-Item processes encrypted files in unencrypted places (xcopy has some ability to do this), and I don't believe Copy-Item supports direct management of archive attributes.

If this is the speed you are looking for, I would suspect that xcopy and robocopy will win. Managed code has higher overall overhead. Xcopy and robocopy also offer much more control over how well they work with the network.

+6
source share

All Articles