powershellconsole

PowerShell find path to currently running host (PowerShell executable)


I can find the path to a running script, but I can't find the path to the running host. I want this because we could be running PowerShell or PowerShell Core 6 or PowerShell Core 7 from a given script, which could be running on Windows or Linux. Googling around this is not obvious (I just get pages telling me how to find the path to the running script). Does anyone know how to find the path to the running host?


Solution

  • To determine the full path of the executable that launched the process in which PowerShell runs:

    # Works with both PowerShell editions, on all platforms.
    (Get-Process -Id $PID).Path
    

    Automatic variable $PID contains the current process' PID (process ID).

    Note: