Identifying PowerShell Host and Path

by Oct 13, 2020

Here is a quick one-liner that identifies the full path to your current PowerShell host:

 
PS> (Get-Process -Id $pid).Path 
C:\Program Files\PowerShell\7\pwsh.exe
 

The path tells you where your current host is located, and you can check whether your code is being executed in Windows PowerShell, PowerShell 7, or the PowerShell ISE.

In a similar approach, you can also find out the path of executables by name. For example, if you wanted to know where PowerShell 7 is installed on your system, try this:

 
PS C:\> (Get-Command -Name pwsh).Source
C:\Program Files\PowerShell\7\pwsh.exe 
 

Of course, this line produces an error if the executable cannot be found. It must be located in one of the folders listed in $env:path.


Twitter This Tip! ReTweet this Tip!