簡體   English   中英

如何獲取由另一個 Powershell 進程打開的 Powershell 進程?

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

我一次運行多個 PowerShell 腳本。 我希望能夠在打開新腳本之前等待某些腳本完成。 基本上,我在想是否可以找到運行它的命令行選項,例如“ powershell.exe -Path "<script dir> ”可以做到這一點。

我試着做一個Get-Process | gm Get-Process | gm找到我可以調用以獲取該信息的任何參數,但我沒有看到任何參數(並不意味着它們不存在)我嘗試通過任務管理器查看是否可以通過 gui 查看某些內容鏈接到,但這也沒有幫助。

我希望我能得到類似的東西

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

我需要等到該過程完成,但我不想在 Start-Process 結束時等待,因為在 Start-Process 啟動之后,我需要在我的 .\\ 運行時轉到其他一些項目。 我只需要在腳本的另一部分開始之前等待它。

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

和 $PID 自動變量,這將給出當前 PowerShell 會話的進程 ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM