Share via


How to find PID of background-job(Start-job)

Question

Friday, February 15, 2019 7:28 AM

I'm doing something background-job(Start-job) with PowerShell.

And I have many background-jobs. However I can't find PID of each jobs but Id of jobs.

Is there any good solution for it with PowerShell?

All replies (4)

Tuesday, February 19, 2019 8:31 AM ✅Answered | 1 vote

Receive-Jon does not return the PID of the PowerShell instance that ran the job.  The example is just using Get-Process as an example of how to retrive the job results.

There is no way to get the PID of the job's process.  You can get the PID of the launching PowerShell and use it to get the its child processes before the job completes.

\(ツ)_/


Tuesday, February 19, 2019 8:38 AM ✅Answered | 1 vote

This will get all running child processes of the current PowerShell session that are "powershell.exe" processes.

Get-WmiObject win32_process -filter "Name='powershell.exe' AND ParentProcessId=$PID"

\(ツ)_/


Monday, February 18, 2019 6:13 AM

Hi,

According to your description, your issue is more related about Windows PowerShell. And this forum is discussing and asking questions about the Windows Form and ClickOnce. I will move this thread to corresponding forum: Windows PowerShell for dedicated information.

Thank you for your understanding.

Regards,

Kyle

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Tuesday, February 19, 2019 7:43 AM

Hi,

Thanks for your question.

Please refer the link below:

https://blogs.technet.microsoft.com/heyscriptingguy/2012/12/31/using-windows-powershell-jobs/

After job completed, you can use "receive-job" cmdlet get process id.

Best Regards,

Lee

Just do it.