Get path to the user home directory on Windows in PowerShell?

Viewed 4184

I am trying to get the path to the current user's home directory (e.g. C:\Users\User1) while respecting different localizations of Windows (which have a different name for the Users folder).

I have seen solutions in Batch, but isn't there a clean way of doing it in PowerShell?

1 Answers

Use the environment variable $env:USERPROFILE.

For example:

cd "$env:USERPROFILE\Downloads"

will take you to the user's Downloads folder (given that it's named "Downloads").]

Related