October 12th, 2014

PowerTip: Find Name of PowerShell Host

Doctor Scripto
Scripter

Summary: Learn to find the name of the Windows PowerShell host.

Hey, Scripting Guy! Question How can I determine if I am running a Windows PowerShell script in the Windows PowerShell console?

Hey, Scripting Guy! Answer Use the Get-Host cmdlet. Here is how to check:

  if((Get-Host).name -ne "consolehost") {"Take appropriate action here"}

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.