のためのオブジェクトを作成しました。
function Copy-AsParallelJod {
param (
[Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory = $true, Position = 0)]
[ValidateScript({ $_ | Test-Path })]
[string]$Source,
[Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory = $true, Position = 1)]
[Alias('Dest')]
[string]$Destination,
$MaxRunningJob = 4,
$MaxThreadByJob = 8
)
begin {
$Start = Get-Date
write-Host (get-date $Start -format 'yyyy/MM/dd HH:mm:ss') -back Magenta
# get-job | Remove-Job -Force
}
process {
while ((Get-Job -State Running | ?{$_.Name -like "Copy_*"}).count -ge $MaxRunningJob) {
# Write-host "Parallelisation CopyJob","Deja $MaxRunningJob en cour"
# Start-Sleep -Seconds 3
wait-Job -Name 'Copy_*' -Any | Receive-Job -AutoRemoveJob -Wait
}
$WorkName = (($Destination.split('\'))[-2..-1]) -join(' ')
Write-Color 'Start-Job',' : ',$Source.padleft(40),' => ',$Destination.padright(40),' @ ',(get-date -format 'yyyy/MM/dd HH:mm:ss') white,red,Magenta,red,yellow,red,green
Start-Job -ScriptBlock {
param($Source, $Dest, $log="/LOG+:C:\MAJ\SuiteExpert.log.txt", $MaxThread)
$Start = Get-Date
New-Item -Path $dest -type Directory -Force | Out-Null
[System.Threading.Thread]::CurrentThread.Priority = 'Lowest'
$PathIdentity = ($Dest.split('\')[-2..-1]) -join('\')
# write-host " +$([char]45)> Job RoboCopy Start [$(get-date $start -format 'yyyy/MM/dd HH:mm:ss')]",$PathIdentity
Robocopy $Source $Dest /E $log /TEE /MT:$MaxThread /S /DCOPY:DA /COPY:DAT /R:3 /W:2 | Out-Null
Start-Sleep -Seconds 1
$Time = (Get-Date) - $start
$Time = "$($time.Hours)h $("$($time.Minutes)".padleft(2,'0'))m $("$($time.Seconds)".padleft(2,'0'))s"
write-host "$dest ",(get-date $start -format 'yyyy/MM/dd HH:mm:ss'),"[$Time]"
} -ArgumentList $Source,$Destination,"/LOG+:$(split-path $Destination)\SuiteExpert($(get-date -format 'yyyy.MM.dd HH.mm'))-$WorkName.log.txt",$MaxThreadByJob -name Copy_$WorkName | Out-Null
Start-Sleep -Milliseconds 500
}
end {
Write-host 'Les deriere copies sont en cour','Encore quelques instants...'
Get-Job -Name 'Copy_*' | Receive-Job -AutoRemoveJob -Wait
$Time = (Get-Date) - $start
$Time = "$($time.Hours)h $("$($time.Minutes)".padleft(2,'0'))m $("$($time.Seconds)".padleft(2,'0'))s"
write-Host "$(get-date -format 'yyyy/MM/dd HH:mm:ss') [$Time]" -back Magenta
}
}
と私はその
[pscustomobject][ordered]@{
Source = 'C:\Data1'
Dest = 'D:\Data1'
},
[pscustomobject][ordered]@{
Source = 'C:\Data1'
Dest = 'D:\Data2'
},
[pscustomobject][ordered]@{
Source = 'C:\Data1'
Dest = 'D:\Data3'
} | Copy-AsParallelJod -MaxRunningJob 4 -MaxThreadByJob 8
なぜdownvoteのようにそれを呼び出します? – Alban