Samselvaprabu
Samselvaprabu

Reputation: 18137

How to do multithread copy using powershell?

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?

Upvotes: 2

Views: 10279

Answers (3)

Chand
Chand

Reputation: 320

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

Upvotes: 1

Andy Arismendi
Andy Arismendi

Reputation: 52567

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.

Upvotes: 3

sarnold
sarnold

Reputation: 104020

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.

Upvotes: 2

Related Questions