In windows cmd I could echo any environmental variable with echo %VARIABLENAME%
, such as
But in powershell, this behavior is inconsistent and I could not understand. For certain variables like $HOME
I could do the same thing (echo $VARIABLENAME
) as in windows cmd.
But for some other variables I could not simply echo but have to use .NET's class methods, such like
I would like to:
- Understand the difference between Powershell and windows cmd. Why they behave differently when accessing and printing environmental variables.
- Understand why certain variable is echolable while others are not in powershell. What is the rule behind that.
I am new to powershell. The purpose of this question is not just getting the variable printed, but understanding how things work in powershell and the difference between windows cmd, so that I could better use it.