[powershell] PowerShell에서 콘솔에 환경 변수를 인쇄하는 방법은 무엇입니까?

저는 PowerShell을 사용하기 시작했고 echo시스템 환경 변수를 콘솔에 읽어가는 방법을 알아 내려고 합니다.

아래 중 어느 것도 작동하지 않습니다. 첫 번째는을 인쇄 %PATH%하고 두 번째는 아무것도 인쇄하지 않습니다.

echo %PATH%
echo $PATH



답변

변수 이름 앞에 다음을 붙입니다 env.

$env:path

env드라이브 를 통해 모든 변수를 열거 할 수도 있습니다.

Get-ChildItem env:


답변

Mathias 답변 외에도.

OP에서는 언급하지 않았지만 Powershell 관련 / 관련 내부 변수 도 확인해야하는 경우 다음 을 사용해야합니다 Get-Variable.

$ Get-Variable

Name                           Value
----                           -----
$                              name
?                              True
^                              gci
args                           {}
ChocolateyTabSettings          @{AllCommands=False}
ConfirmPreference              High
DebugPreference                SilentlyContinue
EnabledExperimentalFeatures    {}
Error                          {System.Management.Automation.ParseException: At line:1 char:1...
ErrorActionPreference          Continue
ErrorView                      NormalView
ExecutionContext               System.Management.Automation.EngineIntrinsics
false                          False
FormatEnumerationLimit         4
...

여기에는 프로필 시작 스크립트에서 설정했을 수있는 항목도 포함됩니다.


답변