我一次运行多个PowerShell脚本。我希望能够在打开新脚本之前等待某些脚本完成。基本上,我在考虑是否可以找到运行“ powershell.exe -Path "<script dir>
”之类的命令行选项。
我尝试做一个Get-Process | gm
来查找可以调用以获取该信息的任何参数,但是我没有看到任何参数(并不意味着它们不存在),我尝试通过任务管理器查看如果我可以通过gui查看可以链接到的内容,但那也没有帮助。
我希望我能得到
Start-Process -FilePath ".\<script>.ps1" -ArgumentList "<args>"
do
{
sleep 10
}
until ((Get-Process -ProcessName "PowerShell" | where "<paramater>" -EQ ".\<script>")
我需要等待该过程完成,但是我不想在启动过程结束时等待,因为启动过程启动后,我需要一些其他项目。\在跑。我只需要它等待脚本的另一部分开始。
答案 0 :(得分:1)
看看“作业” cmdlet https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs?view=powershell-6
还有$ PID自动变量,它将给出当前PowerShell会话的进程ID。