Equivalent of "cd %programfiles%" in PowerShell?
environment-variables, powershell
Solution
The principle is:
$Env:variablename
So you might try:
cd $Env:Programfiles
or to temporarily switch working directory to `%Programfiles%\MyApp`:
Push-Location -Path "$Env:Programfiles\MyApp"
#
# command execution here
#
Pop-Location
To list all environment variables you could do:
Get-ChildItem Env:
or use the convenient alias:
ls env:
Problem
In traditional cmd, we can use `cd %programfiles%` to switch directory which usually resolves to `C:\Program Files`. In PowerShell, how can we go to a directory by a environment variable?