gpt4 book ai didi

powershell - 如何获得由另一个Powershell进程打开的Powershell进程?

转载 作者:行者123 更新时间:2023-12-02 23:52:05 24 4
gpt4 key购买 nike

我一次运行多个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>")

我需要等待该过程完成,但是我不想在启动过程的末尾等待,因为启动过程启动后,当我的。\运行时,我还需要执行一些其他操作。我只需要它等待脚本的另一部分开始。

最佳答案

看看“作业” cmdlet https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs?view=powershell-6

和$ PID自动变量,这将给出当前PowerShell session 的进程ID。

关于powershell - 如何获得由另一个Powershell进程打开的Powershell进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57077761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com