Search notes:

PowerShell: the automatic variable $PID

$PID is an automatic variable and contains the process identifier of the process hosting the current PowerShell session.
With the -id option of get-process, it is possible to query some data about the current powershell process:
get-process -id $PID | format-table startTime, path, workingSet
$PID is (apparently?) not available in a module (*.psm1 file). If the current process's id needs to determined in a module, this can be done like so:
$proc_id = [System.Diagnostics.Process]::GetCurrentProcess().Id

Parent process id

In PowerShell, there is no automatic variable that stores the current process's parent process ID (such as $PPID which is seen in (some?) Unix Shells).
However, it is possible to determine the parent process id like so:
$PPID=(get-cimInstance -className win32_process  -filter "processId = $PID").parentProcessId

PowerShell Core

In PowerShell Core, the object returned by get-process has a Parent property which is a System.Diagnostics.Process object referring to the parent process.

See also

Other automatic variables

Index