Private/Test/Test-IsWindowsTerminal.ps1
|
function Test-IsWindowsTerminal { <# .SYNOPSIS Tests if PowerShell is running in Windows Terminal. .DESCRIPTION Checks if the current PowerShell session is running inside Windows Terminal by detecting the presence of the WT_SESSION environment variable. Windows Terminal sets the WT_SESSION environment variable when it launches a shell session, making it a reliable indicator for detection. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean Returns $true if running in Windows Terminal, $false otherwise. .EXAMPLE Test-IsWindowsTerminal Returns $true if the current session is running in Windows Terminal. .EXAMPLE if (Test-IsWindowsTerminal) { Write-Host "Running in Windows Terminal - enhanced features available" } Conditionally executes code when running in Windows Terminal. .EXAMPLE $isWT = Test-IsWindowsTerminal if ($isWT) { # Use Windows Terminal-specific features like advanced color support } Stores the result for later use in the script. .NOTES Windows Terminal is Microsoft's modern, GPU-accelerated terminal application. Detection is based on the WT_SESSION environment variable which contains a unique GUID for each Windows Terminal session. .LINK https://learn.microsoft.com/en-us/windows/terminal/ #> [CmdletBinding()] [OutputType([bool])] param ( ) #requires -Version 5.1 $result = [bool]$env:WT_SESSION Write-Verbose "Checking Windows Terminal: $result" $result } |