2

I am copying folders where size is huge. Copy-Item cmdlet takes more time.

As my system is Windows 2003 , I don't have multithread option in robocopy too.

Is there any way to copy faster using powershell?

1
  • did you tried using robocopy or any another sample with final solution ? Commented Feb 17, 2015 at 8:17

3 Answers 3

3

Samselvaprabu, I didn't see your comment because it was a reply to another user's answer and it needed a @ for me to see it... As requested here is my comment as an answer:

You're probably better off of using a third party tool. Have a look at these. True multithreading in Powershell is tricky. See this code. That will allow multiple threads for a single powershell.exe instance. You can also use background jobs (Start-Job) to implement concurrent processing. However I doubt you'll see any file copy performance boost with these methods. I'd recommend trying the third party tools first.

Sign up to request clarification or add additional context in comments.

Comments

2

Multithreaded copies really make sense only when you have multiple spinning disks or multiple SSD drives. If you only have two spinning disks (source and destination) then multiple threads is just going to increase contention for disk bandwidth and potentially increase the amount of seeking time between reads.

I wouldn't bother unless you're copying from multiple devices or to multiple devices, and even then, probably only if it is multiple devices on source and destination.

2 Comments

I don't know for certain, but a few guesses: Perhaps it uses much more system RAM to get as linear reads and writes as possible. Perhaps it knows a mechanism to ask the filesystem to not commit journal information as often or until the whole operation is done. Perhaps it can use a zero-copy mechanism to avoid ever bringing the data into userspace.
Looks like robocopy with /MT is taking advantage of SMB 2.1 to improve network I/O which is only available in Win 7 and 2008 R2. SMB 2.1 has support for large MTUs (jumbo frames). According to these benchmarks they are getting better performance with local copies too.
1

This is one of the way to copy as job

$files= "c:\temp\file.zip"
$servers =  get-content "c:\temp\servers.txt"
$Jobs = @()
$sb = {
       Param ($Server, $files)
       xcopy $files \\$Server\C$ /Y
      }

foreach($server in $servers)
{
    $Jobs += start-job -ScriptBlock $sb -ArgumentList $server, $files
}
$Jobs | Wait-Job | Remove-Job

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.