Skip to content

Instantly share code, notes, and snippets.

@mercdev
Last active August 29, 2015 14:20
Show Gist options
  • Save mercdev/4c4e57ed1ec97a51476f to your computer and use it in GitHub Desktop.
Save mercdev/4c4e57ed1ec97a51476f to your computer and use it in GitHub Desktop.
Multithreaded file copy (via Robocopy) to multiple destinations
cls
$source = "\\sourcefiles\path\here";
$auth = "\\authserver\c$\Fileroot";
$destDev = "\\devserver\C$\FileRoot";
$destTest = "\\testserver\C$\FileRoot";
$destStage = "\\stageserver\C$\FileRoot";
$destProd = "\\productionserver\C$\FileRoot";
#$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S /NC /NS /NDL /NJH /NJS /NFL }
$scriptBlock = { Param($source,$destination) robocopy $source $destination /MAXAGE:21 /MT:32 /S }
$destDev, $destTest, $destStage, $destProd | ForEach-Object { Start-Job -ScriptBlock $scriptBlock -ArgumentList $auth,$_ }
while (Get-Job -State "Running") { Start-Sleep 5; }
Get-Job | Receive-Job
Remove-Job *
"Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment