如何通过Powershell从远程计算机异步运行Python脚本?

如何通过Powershell从远程计算机异步运行Python脚本?,python,function,powershell,parallel-processing,asynchronous,Python,Function,Powershell,Parallel Processing,Asynchronous,我有一个只同步工作的powershell函数。我想更新这个函数,以便能够并行地对Python脚本发出多个调用。有人知道如何使用powershell异步调用Python脚本吗?请记住,每个Python脚本本质上都是一个while循环,直到24小时过去才结束。powershell函数接收远程计算机、python虚拟环境、python脚本的路径和参数 以下是迄今为止所做的工作: function Run-Remote($computerName, $pname, $scriptPath, $pargs

我有一个只同步工作的powershell函数。我想更新这个函数,以便能够并行地对Python脚本发出多个调用。有人知道如何使用powershell异步调用Python脚本吗?请记住,每个Python脚本本质上都是一个while循环,直到24小时过去才结束。powershell函数接收远程计算机、python虚拟环境、python脚本的路径和参数

以下是迄今为止所做的工作:

function Run-Remote($computerName, $pname, $scriptPath, $pargs)
{
    $cred = Get-QRemote-Credential
    Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock {powershell -c "$Using:pname '$Using:scriptPath' $Using:pargs"} -ConfigurationName QRemoteConfiguration
}

非常简单的修复方法,只需在invoke命令中添加“-AsJob”。这将使powershell为您发送的每个命令启动一个新进程。然后在脚本末尾使用“Get Job | Wait Job”等待所有进程完成。和“获取作业|接收作业”以获取任何数据

我建议阅读有关powershell作业的书籍,它们非常有用,但不直观

function Run-Remote($computerName, $pname, $scriptPath, $pargs)
{
    $cred = Get-QRemote-Credential
    Invoke-Command -AsJob -ComputerName $computerName -Credential $cred -ScriptBlock {powershell -c "$Using:pname '$Using:scriptPath' $Using:pargs"} -ConfigurationName QRemoteConfiguration
}

Get-Job | Wait-Job

杰出的非常感谢。我会尝试一下。我尝试使用AsJob参数,但它没有在任务机中生成python进程。这很奇怪,作业是否正确完成?我能想到的唯一一件事是脚本在作业完成之前退出,而它没有。我改为使用-未连接会话。您是否预见到使用它会有任何问题?