问题
I want to do something special when my PowerShell script is being executed by Windows Terminal and not the normal PowerShell command line or ISE. How to determine that? I checked some built-in variables like $Host
and can't find related information.
回答1:
Disclaimer: Windows Terminal is still in development at this time of writing and this information could change for the stable release.
Look for the $env:WT_SESSION
environment variable - this looks to be set to a GUID in a Windows Terminal session, but not when running powershell.exe
or running powershell.exe
through ConEmu, both of which I also tested.
来源:https://stackoverflow.com/questions/59758146/how-to-determine-if-my-powershell-script-is-being-executed-by-windows-terminal