Recognize the new Windows Terminal from a PowerShell script #3153

Closed
opened 2026-01-30 23:14:14 +00:00 by claunia · 2 comments
Owner

Originally created by @developer82 on GitHub (Aug 5, 2019).

I'm writing a new PowerShell script, and I want to make use of unicode emojies, which are now supported by the new Windows Terminal Preview. However, for a user running "legacy" PowerShell that doesn't support it, I do not wish to show the unrecognized characters, and instead I would like to show him some other text/sign.

To be more simple - I would like to know when my PS script is running in the new Terminal and show one thing and show something else for other PS terminals.

I have tried using $env:TERM_PROGRAM. If I use is inside the vscode PS terminal it returns "vscode", but under normal PS terminal or new terminal it returns nothing.

Any ideas?

Originally created by @developer82 on GitHub (Aug 5, 2019). I'm writing a new PowerShell script, and I want to make use of unicode emojies, which are now supported by the new Windows Terminal Preview. However, for a user running "legacy" PowerShell that doesn't support it, I do not wish to show the unrecognized characters, and instead I would like to show him some other text/sign. To be more simple - I would like to know when my PS script is running in the new Terminal and show one thing and show something else for other PS terminals. I have tried using `$env:TERM_PROGRAM`. If I use is inside the vscode PS terminal it returns "vscode", but under normal PS terminal or new terminal it returns nothing. Any ideas?
claunia added the Resolution-DuplicateIssue-Docs labels 2026-01-30 23:14:14 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Aug 5, 2019):

I believe we added a WT_SESSION environment variable for specifically this purpose.

WT_SESSION=e1d171d9-4739-4cd0-b086-50d729f39631

(where the value is a random GUID generated at runtime, per-terminal instance)

I don't think this is necessarily the right solution but I know it'll work, and I don't have any other ideas at the moment. I know there's some discussion around the idea of TERM_PROGRAM and if it's a good or bad idea somewhere else on this issue tracker, but I'm too lazy to look it up right now.

@zadjii-msft commented on GitHub (Aug 5, 2019): I believe we added a `WT_SESSION` environment variable for specifically this purpose. ``` WT_SESSION=e1d171d9-4739-4cd0-b086-50d729f39631 ``` (where the value is a random GUID generated at runtime, per-terminal instance) I don't think this is necessarily the right solution but I know it'll work, and I don't have any other ideas at the moment. I know there's some discussion around the idea of `TERM_PROGRAM` and if it's a good or bad idea somewhere else on this issue tracker, but I'm too lazy to look it up right now.
Author
Owner

@DHowett-MSFT commented on GitHub (Aug 5, 2019):

This is fundamentally a duplicate of #1040.

@DHowett-MSFT commented on GitHub (Aug 5, 2019): This is fundamentally a duplicate of #1040.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3153