#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.

Filed in: Columns, Tips and Tricks Tags: ,

One Response to "#PSTip Find PowerShell host process name"

  1. Miodrag Milić says:

    Useful when u need to create run/stop command in custom editors. In editplus I use

    powershell -Command “$pid > editplus_powershell_pid; . ‘$(FilePath)’ ”

    powershell -Command “kill -id $(gc editplus_powershell_pid)”

Leave a Reply

Submit Comment

© 8856 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: