Skip to content

Instantly share code, notes, and snippets.

@QZLin
Created October 16, 2025 06:06
Show Gist options
  • Select an option

  • Save QZLin/bbe31fcf6dbfd380981b7a9da0776686 to your computer and use it in GitHub Desktop.

Select an option

Save QZLin/bbe31fcf6dbfd380981b7a9da0776686 to your computer and use it in GitHub Desktop.
powershell pofile include virtual terminal check
function IsVirtualTerminalProcessingEnabled {
$MethodDefinitions = @'
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
'@
$Kernel32 = Add-Type -MemberDefinition $MethodDefinitions -Name 'Kernel32' -Namespace 'Win32' -PassThru
$hConsoleHandle = $Kernel32::GetStdHandle(-11) # STD_OUTPUT_HANDLE
$mode = 0
$Kernel32::GetConsoleMode($hConsoleHandle, [ref]$mode) >$null
if ($mode -band 0x0004) {
# 0x0004 ENABLE_VIRTUAL_TERMINAL_PROCESSING
return $true
}
return $false
}
$CanUsePredictionSource = (! [System.Console]::IsOutputRedirected) -and (IsVirtualTerminalProcessingEnabled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment