July 22nd, 2015

PowerTip: Determine if Running in PowerShell Console

Doctor Scripto
Scripter

Summary: Determine if you are running inside the Windows PowerShell console.

Hey, Scripting Guy! Question How can I find if I am running inside the Windows PowerShell console for my Windows PowerShell profile?

Hey, Scripting Guy! Answer Look at the $host.name property. If it returns ConsoleHost, you are running in the Windows PowerShell console.
           The following code shows how to do this:

if(($host.Name -match 'consolehost')) {$true}

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback