Powershell wait-job 给出错误一个或多个作业被阻止等待用户交互

Powershell wait-job gives error one or more jobs are blocked waiting for user interaction

我有以下命令,$a 有 20 个 URL:

$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

低于错误:

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

参考 Link : input objects in powershell jobs

请帮我解决错误,提前致谢!!

您的代码唯一明显的问题(可能是发布工件)是您的 Start-Job 脚本块中有第二个无关的 -ArgumentList $a1 - 但这会导致不同的错误,尽管可能会被您得到的那个抢占。


听起来像您的一项工作意外提示用户输入,正如错误消息所暗示的那样。

如错误消息中所建议,使用 Receive-Job 会将交互式提示带到前台,以便您查看和响应它们。

这应该可以帮助您诊断是哪个作业导致了问题以及原因;这是一个简化的例子:

# 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