Hello all,
I am new to PowerShell jobs but I have a problem that I am trying to solve - and if I understand them correctly, I think it is a proper use. Ultimately, I have to upgrade firmware on 300+ routers. I have a script that will do this now in series, which will take a long time. I am thinking that if done in parallel it will be more efficient.
I have a script that will start a job, uniquely named for each router, SSH to the router, run a command, and schedule a reboot. I am using the Posh-Junos module to work with my routers (GitHub - scottdware/Posh-Junos: Powershell module to interact with Junos devices.).
My question is - when I run my script that creates the jobs, the output on the screen shows that all of the jobs are being created (45 in my script), but my powershell prompt does not return for almost 2 minutes after the last job is created. Why is this?
Here is the script I am using.
$routers = Import-Excel -path '.\routers.xlsx' -WorkSheetname routers | Where-Object { $_.active -eq $true } | Select-Object -Property Shop, Router Import-Module Posh-Junos $count = 15 foreach($r in $routers | select -First ($count * 3)) { $shop = $r.shop $jobname = "RunCommands-$shop" $block = { param($srx) $user = '***' $pass = '***' Write-Host "Connecting to:" $srx Invoke-JunosCommand -Device $srx ` -User $user ` -Password $pass ` -Command 'request system software add /var/tmp/fw.tgz;request system reboot at 201701050100' } Start-Job -Name $jobname -ScriptBlock $block -ArgumentList $r.Router }
Any input is appreciated.
Thanks,
sb