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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758186675, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/variable/automatic/PID(58): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78