Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "cd %programfiles%" in PowerShell?

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?

like image 253
Gqqnbig Avatar asked Nov 22 '13 06:11

Gqqnbig


People also ask

How do I get the PATH environment variable in PowerShell?

Environment variables in PowerShell are stored as PS drive (Env: ). To retrieve all the environment variables stored in the OS you can use the below command. You can also use dir env: command to retrieve all environment variables and values.

What does CD stand for in PowerShell?

The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.


1 Answers

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: 
like image 55
ErikE Avatar answered Sep 29 '22 15:09

ErikE