omnipower321
asked on
Powershell 1 to many file copy
Hello,
I have a need to copy a large file to several hundred hosts to prep for the installation of said file. The file is a couple of GB. I was running the following:
ForEach($strServer in (GC .\Servers.txt)){
Copy-Item "\\SERVER1\SHARE\File.exe" -Destination "\\$strServer\C$\Temp"
}
Which works fine, but is obviously doing the copies one at a time, which is taking ~4 minutes per file times several hundred servers.
Is there a quick way to get 5 to 10 copies happening at the same time, with verification that the file copied successfully?
Thank you for any information or direction.
I have a need to copy a large file to several hundred hosts to prep for the installation of said file. The file is a couple of GB. I was running the following:
ForEach($strServer in (GC .\Servers.txt)){
Copy-Item "\\SERVER1\SHARE\File.exe"
}
Which works fine, but is obviously doing the copies one at a time, which is taking ~4 minutes per file times several hundred servers.
Is there a quick way to get 5 to 10 copies happening at the same time, with verification that the file copied successfully?
Thank you for any information or direction.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the responses. I have been trying with Start-Job, but am having some trouble figuring out a way to control how many active threads are copying.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I ended up with. Seems to be working well so far. Thank you both for the input!
$intThreadCount = 5
Get-Job | Stop-Job
Get-Job | Remove-Job
Function Get-ActiveThreads{
$strHost = $Args[0]
If((@(Get-Job | ?{$_.State -eq "Running"}).Count) -lt $intThreadCount){
Start-Job -Name $strHost -Scriptblock {Copy-Item "\\SERVER1\SHARE\File.exe" -Destination "\\$($args[0])\C`$\Temp"} -ArgumentList $strHost
}
Else{
Start-Sleep 1
Get-ActiveThreads $strHost
}
}
ForEach($strHost in (GC .\Hosts.txt)){
Get-ActiveThreads $strHost
}
http://technet.microsoft.com/en-us/library/dd347692.aspx
Or maybe you could user remote execution to have the machines copy it themselves:
http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/55c7c141-56e7-4bc3-914d-72c7550fa815