I have below command, $a have 20 URLs:
$a = @('http://10.10.10.101/Login.aspx',
'http://10.10.10.101/user/customers')
$startFulltime = (Get-Date)
foreach($a1 in $a){
start-job -ArgumentList $a1 -ScriptBlock{
param($a1)
Invoke-WebRequest $a1 -Method post -DisableKeepAlive -UseBasicParsing
-ArgumentList $a1
}}
Get-Job | Wait-Job
Getting Below Errors:
Wait-Job : The Wait-Job cmdlet cannot finish working, because one or more jobs are blocked waiting for user interaction. Process interactive job
output by using the Receive-Job cmdlet, and then try again.
At line:13 char:11
Get-Job | Wait-Job
~~~~~~~~
CategoryInfo : Deadlock detected: (System.Manageme...n.PSRemotingJob:PSRemotingJob) [Wait-Job], ArgumentException
FullyQualifiedErrorId : BlockedJobsDeadlockWithWaitJob,Microsoft.PowerShell.Commands.WaitJobCommand
Reference Link : input objects in powershell jobs
Please help me to resolve error, thanks In Advance!!
CodePudding user response:
The only obvious problem with your code - which may be a posting artifact - is that there's a second, extraneous -ArgumentList $a1
inside your Start-Job
script block - but that would cause a different error, though potentially preempted by the one you're getting.
It sounds like one of your jobs unexpectedly prompts for user input, as implied by the error message.
Use of Receive-Job
, as suggested in the error message, will bring interactive prompts to the foreground, allowing you to see and respond to them.
This should help you diagnose which job causes the problem and why; here's a simplified example:
# Start a job with a command that asks the user for interactive input
# (which isn't a good idea).
$job = Start-Job { Read-Host 'Enter something' }
# !! Error, because the job is waiting for interactive user input.
$job | Wait-Job
# OK - Receive-Job "foregrounds" the Read-Host prompt.
# Once you respond to it, the job finishes
# (and is automatically removed here, thanks to -Wait -AutoRemoveJob).
$job | Receive-Job -Wait -AutoRemoveJob