显示正在运行的 PowerShell 脚本中的所有环境变量 [英] Display all environment variables from a running PowerShell script

查看:23
本文介绍了显示正在运行的 PowerShell 脚本中的所有环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行时在 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

这将显示名称和值.

这篇关于显示正在运行的 PowerShell 脚本中的所有环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆