脚本可以确定自己的进程吗?

Can a script determine its own process?

假设您有一个可以同时在多个实例中启动的 PowerShell 脚本。这些脚本有什么方法可以识别每个脚本是哪个进程运行?

基本上,我正在寻找像虚构的东西:

$MyInvocation.processID

谢谢。

使用$PID自动变量:

$ThisProcess = Get-Process -Id $PID