简体   繁体   English

如何获取由另一个 Powershell 进程打开的 Powershell 进程?

[英]How do I get a Powershell process that was opened by another Powershell process?

I am running multiple PowerShell scripts at once.我一次运行多个 PowerShell 脚本。 I would like to be able to wait on certain ones to finish before opening new scripts.我希望能够在打开新脚本之前等待某些脚本完成。 Basically, I was thinking if I could find the command line option that ran it something like " powershell.exe -Path "<script dir> " that would do it.基本上,我在想是否可以找到运行它的命令行选项,例如“ powershell.exe -Path "<script dir> ”可以做到这一点。

I tried doing a Get-Process | gm我试着做一个Get-Process | gm Get-Process | gm to find any parameters that I could call to get that information and I didn't see any (doesn't mean they aren't there) I tried looking through Task Manager to see if I could view something through the gui that I could link to but that didn't help either. Get-Process | gm找到我可以调用以获取该信息的任何参数,但我没有看到任何参数(并不意味着它们不存在)我尝试通过任务管理器查看是否可以通过 gui 查看某些内容链接到,但这也没有帮助。

I hope I can get something like我希望我能得到类似的东西

Start-Process -FilePath ".\<script>.ps1" -ArgumentList "<args>"
do
{
    sleep 10
}
until ((Get-Process -ProcessName "PowerShell" | where "<paramater>" -EQ ".\<script>")

I need to wait until that process is done but I don't want to put a wait at the end of the Start-Process because after that Start-Process kicks off I need some other items to go to while my .\\ is running.我需要等到该过程完成,但我不想在 Start-Process 结束时等待,因为在 Start-Process 启动之后,我需要在我的 .\\ 运行时转到其他一些项目。 I just need it to wait before another section of script kicks off.我只需要在脚本的另一部分开始之前等待它。

Have a look at the "Job" cmdlets https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs?view=powershell-6查看“作业”cmdlet https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_jobs?view=powershell-6

And the $PID automatic variable, this will give the process ID of the current PowerShell session.和 $PID 自动变量,这将给出当前 PowerShell 会话的进程 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM