How to determine if my PowerShell script is being executed by Windows Terminal?

a 夏天 提交于 2020-12-31 05:49:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!