Teknowledgist
Teknowledgist

Reputation: 403

Can a script determine its own process?

Say you have a single PowerShell script that can be started in multiple, simultaneous instances. Is there any way for those scripts to identify which process each of them is running?

Basically, I'm looking for something like an imaginary:

$MyInvocation.processID

Thanks.

Upvotes: 0

Views: 28

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174990

Use the $PID automatic variable:

$ThisProcess = Get-Process -Id $PID

Upvotes: 1

Related Questions