Accessing PowerShell Host Process

by Jan 18, 2013

With this line, you always get back the process object representing the current PowerShell host:

PS> [System.Diagnostics.Process]::GetCurrentProcess()

This is the equivalent to:

PS> Get-Process -ID $PID

Either way, the process object returned can provide useful information like the host that runs your script, or the total time the process has been running:

PS> [System.Diagnostics.Process]::GetCurrentProcess().Description
Windows PowerShell ISE
PS> (Get-Process -ID $PID).Description
Windows PowerShell ISE

Twitter This Tip! ReTweet this Tip!