且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何确定Windows终端是否正在执行我的PowerShell脚本?

更新时间:2023-12-04 21:41:10

免责声明:在撰写本文时,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.