For an important data migration, I would like to execute in parallel multiple scripts in side subfolders :
I did not succeed to do this :
$folders = Get-ChildItem -Directory
foreach($folder in $folders){
$cmd = "powershell '$folder\script.ps1'"
$job = start-job -ScriptBlock {Invoke-Expression $cmd}
}
Thank you for your help!
You can use Here's an example that may meet your requirements.Invoke-Command
for concurrent processing.
Get-ChildItem -Directory | ForEach-Object {
$folderPath = $_.FullName
Start-Job -ScriptBlock { .\script.ps1 $using:folderPath }
}
Get-Job | ForEach-Object {
$result = Wait-Job $_ | Receive-Job
Remove-Job $_
$result
}