Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 471
YorSubs Avatar asked Aug 29 '26 16:08

YorSubs


1 Answers

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:

  • On Unix platforms, if PowerShell was started via a symlink, the above reports the actual location of the executable, not that of the symlink.

  • In PowerShell (Core) 7, you may alternatively use the following:

    # PowerShell 7.2+ only.
    [Environment]::ProcessPath
    
like image 105
mklement0 Avatar answered Aug 31 '26 07:08

mklement0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!