Skip to content

Instantly share code, notes, and snippets.

@sba923
Last active April 26, 2026 14:35
Show Gist options
  • Select an option

  • Save sba923/c41f97a5f4ea15c957227712f42b14f3 to your computer and use it in GitHub Desktop.

Select an option

Save sba923/c41f97a5f4ea15c957227712f42b14f3 to your computer and use it in GitHub Desktop.
PowerShell utilities for Windows Terminal
# this is one of Stéphane BARIZIEN's public domain scripts
# the most recent version can be found at:
# https://gist.github.com/sba923/c41f97a5f4ea15c957227712f42b14f3#file-get-windowsterminalversion-ps1
# cSpell: ignore wekyb bbwe Stéphane BARIZIEN
<#
.SYNOPSIS
Returns the Windows Terminal version for the current PowerShell session host chain.
.DESCRIPTION
Walks up the current process parent chain to detect whether PowerShell is running
inside Windows Terminal. If a WindowsTerminal process is found, returns its file
version and whether the detected package flavor is Preview.
If no WindowsTerminal parent process is found, the script returns $null.
.OUTPUTS
System.Management.Automation.PSCustomObject
When found, returns an object with:
- Version
- IsPreview
Returns $null when not running in Windows Terminal.
.EXAMPLE
Returns the detected Windows Terminal version and flavor information for the current
session, or $null if this session is not hosted by Windows Terminal.
Get-WindowsTerminalVersion.ps1
#>
$psPID = [System.Diagnostics.Process]::GetCurrentProcess() | Select-Object -ExpandProperty ID
$process = Get-Process -Id $psPID
$isWinPS = ($PSVersionTable.PSVersion.Major -eq 5)
while ($true)
{
if ($isWinPS)
{
$parentPID = (Get-CimInstance Win32_Process | Where-Object ProcessID -eq $process.Id).ParentProcessId
if ($null -ne $parentPID)
{
$parent = Get-Process -Id $parentPID
}
else
{
$parent = $null
}
}
else
{
$parent = $process.Parent
}
if ($null -eq $parent)
{
$wtVersion = $null
break
}
if ($parent.Name -eq 'WindowsTerminal')
{
$wtVersion = $parent.FileVersion
$wtFlavor = $parent.Path -replace '.*Microsoft\.([^_]+)_.*__8wekyb3d8bbwe\\WindowsTerminal.exe', '$1'
break
}
$process = $parent
}
if ($null -eq $wtVersion)
{
$null
}
else
{
[PSCustomObject]@{
Version = $wtVersion
IsPreview = ($wtFlavor -match 'Preview')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment