#PSTip Find PowerShell host process name

Note: This tip requires PowerShell 2.0 or above.

Every PowerShell host implements the $pid automatic variable which refers to the process ID of the PowerShell host process. Using it, we can find the name of the PowerShell host process within a script or a command.

(Get-Process -Id $pid).Name

The above snippet outputs process name such as powershell and powershell_ise for PowerShell.exe and PowerShell_ISE.exe respectively. Or any other process name depending on the script editor (such as PowerShell Plus, etc) or the PowerShell host you have installed.

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts

%d bloggers like this: