Monthly Archive

Categories

Monthly Archives: August 2019

Identifying the host

Identifying the host in which your PowerShell code is running could be important. For instance you might not want to run some code that takes a long time to complete in VSCode – you may prefer to ensure it runs in the console as it consumes fewer resources.

 

You can identify the host – most of the time – using $host

 

For the PowerShell console – Windows PowerShell or PowerShell Core

PS> $host.Name
ConsoleHost

 

For ISE – Windows PowerShell

PS> $host.Name
Windows PowerShell ISE Host

 

For VScode – Windows PowerShell or PowerShell Core

PS> $host.Name
Visual Studio Code Host

 

For the new Windows Terminal – Windows PowerShell or PowerShell Core

PS> $host.Name
ConsoleHost

If you need to differentiate between the traditional PowerShell console and the new Windows terminal you’ll find that the Windows terminal adds an environmental variable

WT_SESSION

which takes a value of the form - 407c1756-556e-4df2-97db-c159a616b237

PowerShell Day UK 2019

The PowerShell Day UK 2019 one day conference is on Saturday 28 September 2019 - https://psday.uk/

 

I’ll be speaking and willing to answer any PowerShell questions that I can during the breaks.

 

If you have any books of mine that you want signing – bring them along and I’ll be happy to oblige.