Run parallel Invoke-WebRequest jobs in PowerShell v3 Run parallel Invoke-WebRequest jobs in PowerShell v3 powershell powershell

Run parallel Invoke-WebRequest jobs in PowerShell v3


You need to pass in the parameters in such as way that they actually make it into the job. In V3, you can use the $using: syntax to do this:

for($f=0;$f -lt $urlList.Count;$f++){    $remote = $urlList[$f] + $fileList[$f]    $local = 'C:\folder\' + $fileList[$f]    Start-Job {Invoke-WebRequest $using:remote -Method Get -OutFile $using:local -UserAgent FireFox}}Get-Job|Wait-Job

BTW you don't need to use Invoke-Expression. Just put the code you want to run in a job inside a scriptblock i.e. a set of curly braces {...}.