Identify when PowerShell is running within Windows Terminal #14290

Closed
opened 2026-01-31 04:06:21 +00:00 by claunia · 5 comments
Owner

Originally created by @mileso on GitHub (Jun 21, 2021).

There is, by design, no reliable way. We have been hoping for someone to come along and explain what their use case would be for being able to determine that 😄

Originally posted by @DHowett-MSFT in https://github.com/microsoft/terminal/issues/5523#issuecomment-618809182

I'm your huckleberry 😀

Here is my use case:

Set a different window title when running PowerShell within Windows Terminal. Windows Terminal has less real estate because the title is displayed on a tab so I'd like to set a shorter title only when running under Windows Terminal.

Simple example: Add the path to the title only when not running within Windows Terminal.

Originally created by @mileso on GitHub (Jun 21, 2021). There is, by design, no reliable way. We have been hoping for someone to come along and explain what their use case would be for being able to determine that 😄 _Originally posted by @DHowett-MSFT in https://github.com/microsoft/terminal/issues/5523#issuecomment-618809182_ I'm your huckleberry 😀 Here is my use case: Set a different window title when running PowerShell within Windows Terminal. Windows Terminal has less real estate because the title is displayed on a tab so I'd like to set a shorter title only when running under Windows Terminal. Simple example: Add the path to the title only when not running within Windows Terminal.
claunia added the Issue-QuestionNeeds-TriageNeeds-Tag-FixResolution-Answered labels 2026-01-31 04:06:21 +00:00
Author
Owner

@mileso commented on GitHub (Jun 21, 2021):

Here is my current work-around (I placed these lines in my profile script):

$parentProcess = (Get-Process -Id (gwmi win32_process -Filter "processid='$PID'").ParentProcessId)
$isWT = ($parentProcess.Name -like "Win*Term*")

@mileso commented on GitHub (Jun 21, 2021): Here is my current work-around (I placed these lines in my profile script): `$parentProcess = (Get-Process -Id (gwmi win32_process -Filter "processid='$PID'").ParentProcessId)` `$isWT = ($parentProcess.Name -like "Win*Term*")`
Author
Owner

@skyline75489 commented on GitHub (Jun 22, 2021):

how does this https://github.com/microsoft/terminal/issues/1040#issuecomment-496691842 sounds to you?

@skyline75489 commented on GitHub (Jun 22, 2021): how does this https://github.com/microsoft/terminal/issues/1040#issuecomment-496691842 sounds to you?
Author
Owner

@mileso commented on GitHub (Jun 22, 2021):

how does this #1040 (comment) sounds to you?

If you spawn a shell from within a Windows Terminal session it will inherit the WT environment variables so environment variables are not a solution. Or am I missing something from that discussion?

See: https://github.com/microsoft/terminal/issues/5523#issuecomment-619289717

@mileso commented on GitHub (Jun 22, 2021): > how does this [#1040 (comment)](https://github.com/microsoft/terminal/issues/1040#issuecomment-496691842) sounds to you? If you spawn a shell from within a Windows Terminal session it will inherit the WT environment variables so environment variables are not a solution. Or am I missing something from that discussion? See: https://github.com/microsoft/terminal/issues/5523#issuecomment-619289717
Author
Owner

@MartinGC94 commented on GitHub (Jun 22, 2021):

He also made a suggestion to check the parent process: (Get-Process -Id $PID).Parent.Name -eq "WindowsTerminal" this should never have false positives but it may have false negatives if you open up a nested process inside the terminal.

@MartinGC94 commented on GitHub (Jun 22, 2021): He also made a suggestion to check the parent process: `(Get-Process -Id $PID).Parent.Name -eq "WindowsTerminal"` this should never have false positives but it may have false negatives if you open up a nested process inside the terminal.
Author
Owner

@zadjii-msft commented on GitHub (Jul 6, 2021):

I mean, you can always just make the tabs wider too. See "tabWidthMode": "titleLength". If you're the kind of person who wants to put info into the terminal title, then you probably what the whole tab to be visible 😄

@zadjii-msft commented on GitHub (Jul 6, 2021): I mean, you can always just make the tabs wider too. See [`"tabWidthMode": "titleLength"`](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/appearance#tab-width-mode). If you're the kind of person who wants to put info into the terminal title, then you probably what the whole tab to be visible 😄
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14290