Change to home directory in PowerShell

15

3

At the cmd command prompt, this command will take me to my home directory:

cd %UserProfile%

At the PowerShell command prompt, the same command produces this error:

Set-Location : Cannot find path 'C:\%UserProfile%' because it does not exist.
At line:1 char:3
+ cd <<<<  %UserProfile%
    + CategoryInfo          : ObjectNotFound: (C:\%UserProfile%:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

What is the equivalent command in PowerShell?

Iain Samuel McLean Elder

Posted 2012-07-08T00:58:44.067

Reputation: 649

Answers

28

You can get to your home dir with this command:

cd $home

imtheman

Posted 2012-07-08T00:58:44.067

Reputation: 3 503

5As an add-on to this answer, %UserProfile% does not literally translate to $home, and, instead, you should use the $env:UserProfile variable. – SpellingD – 2012-07-19T15:57:45.197

12

This shorthand is one of my favorites:

cd ~

You can also do:

cd ~\Deskt 

(Hit the Tab key to auto-complete, it works nicely when you are buried in some deep directory and need to copy something to Desktop or somewhere in your $HOME)

yaxzone

Posted 2012-07-08T00:58:44.067

Reputation: 121

Nice, somehow I didn't know you could use ~ in PowerShell! – Nate Barbettini – 2015-12-01T00:52:48.773