显示正在运行的PowerShell脚本中的所有环境变量 [英] Display all environment variables from a running PowerShell script
问题描述
我需要在运行时在PowerShell脚本中显示所有已配置的环境变量.通常,在显示环境变量时,我可以在shell上使用以下选项之一(除其他技术外,这些都很简单):
I need to display all configured environment variables in a PowerShell script at runtime. Normally when displaying environment variables I can just use one of the following at the shell (among other techniques, but these are simple):
gci env:*
ls Env:
但是,我有一个脚本是从另一个程序中调用的,当我在脚本中使用上述调用之一时,我没有得到环境变量及其值,而是得到了一个System.Collections.DictionaryEntry
类型的列表.变量及其值.在PowerShell脚本中,如何显示所有环境变量?
However, I have a script being called from another program, and when I use one of the above calls in the script, instead of being presented with environment variables and their values, I instead get a list of System.Collections.DictionaryEntry
types instead of the variables and their values. Inside of a PowerShell script, how can I display all environment variables?
推荐答案
更短版本:
gci env:* | sort-object name
这将同时显示名称和值.
This will display both the name and value.
这篇关于显示正在运行的PowerShell脚本中的所有环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!