如何确定Windows终端是否正在执行我的PowerShell脚本? [英] How to determine if my PowerShell script is being executed by Windows Terminal?
问题描述
当我的PowerShell脚本由 Windows Terminal 执行时,我想做一些特别的事情,正常的PowerShell命令行或ISE.如何确定呢?我检查了一些内置变量,例如 $ Host
,找不到相关信息.
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.
推荐答案
免责声明:在撰写本文时,Windows Terminal仍在开发中,此信息可能会因稳定发行版而更改.
Disclaimer: Windows Terminal is still in development at this time of writing and this information could change for the stable release.
查找 $ env:WT_SESSION
环境变量-在Windows Terminal会话中,该变量似乎设置为GUID,但在运行 powershell.exe
或运行时则未设置通过ConEmu的 powershell.exe
,我也都进行了测试.
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.
这篇关于如何确定Windows终端是否正在执行我的PowerShell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!