Skip to main content

How to Get Your Home Folder in PowerShell with $HOME

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

$HOME holds the full path of your home folder. This guide prints it, builds paths inside it, goes there with Set-Location, and shows where its value comes from, with real output from PowerShell 7.6.10.

PowerShell sets $HOME for you. It's one of the automatic variables, which the about_Automatic_Variables page describes as "variables that store state information for and are created and maintained by PowerShell." Of $HOME, the page says: "Contains the full path of the user's home directory."

Syntax​

Syntax
$HOME
Join-Path $HOME '<name>'
"$HOME/<name>"
PartWhat it means
$HOMEThe automatic variable that holds the full path of your home folder
Join-Path $HOME '<name>'Builds the path of a file or folder inside your home folder
<name>The name of the file or folder, such as Documents
"$HOME/<name>"The same path written as text: inside double quotes, $HOME is replaced by its value

The Example​

The example prints the home folder of the user running PowerShell, and builds the path of the Documents folder inside it. The commands run in the PowerShell 7.6.10 console on a Mac.

Prerequisites​

  • PowerShell 7. This guide uses PowerShell 7.6.10: $PSVersionTable.PSVersion.ToString() printed 7.6.10.

Step 1: Print Your Home Folder​

PowerShell
$HOME
Output
/Users/you

A variable's name on its own prints its value: here, the full path of the home folder. Your own user name appears where this shows you.

Step 2: Build a Path Inside Your Home Folder​

PowerShell
Join-Path $HOME 'Documents'
"$HOME/Documents"

macOS-style code window titled PowerShell with two ways to build the path of the Documents folder inside the home folder: Join-Path $HOME 'Documents', and $HOME/Documents written in double quotes.

Output
/Users/you/Documents
/Users/you/Documents

Both lines built the same path. Join-Path added the / between the home folder and the folder name. The Join-Path page: "The Join-Path cmdlet combines a path and child-path into a single path. The provider supplies the path delimiters."

The second line is text in double quotes, so PowerShell put the value of $HOME in place of its name. The about_Quoting_Rules page: "A string enclosed in double quotation marks is an expandable string. Variable names preceded by a dollar sign ($) are replaced with the variable's value before the string is passed to the command for processing."

macOS-style terminal window titled PowerShell where $HOME prints /Users/you, and both Join-Path $HOME 'Documents' and $HOME/Documents written in double quotes print /Users/you/Documents.

Step 3: Go to Your Home Folder​

PowerShell
Set-Location $HOME
Get-Location
Output
Path
----
/Users/you

Set-Location made the home folder the current location and printed nothing. Get-Location then printed the current location, now /Users/you. The Set-Location page: "The Set-Location cmdlet sets the working location to a specified location."

Step 4: See Where the Value Comes From​

PowerShell
$env:HOME
Output
/Users/you

$env:HOME reads the HOME environment variable. The about_Environment_Variables page: "Environment variables store data that's used by the operating system and other programs." In $env:HOME, "the dollar sign ($) indicates a variable, and the drive name (Env:) indicates an environment variable followed by the variable name".

It printed the same path as $HOME. macOS is a Unix system, and the about_Automatic_Variables page says of $HOME: "On Unix, this variable uses the value of the HOME environment variable."

Common Mistakes​

MistakeWhat happensDo this instead
Single quotes: '$HOME/Documents'It printed $HOME/Documents: the name, not the pathUse double quotes, or Join-Path
Joining with +: $HOME + 'Documents'/Users/youDocuments, with no / between the twoUse Join-Path $HOME 'Documents'
A colon right after the name: "$HOME: my home folder"ParserError: Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.Put the name in braces: "${HOME}: my home folder" printed /Users/you: my home folder
Changing it: $HOME = '/tmp'WriteError: Cannot overwrite variable HOME because it is read-only or constant., and $HOME still printed /Users/youKeep other paths in a variable of your own

The about_Quoting_Rules page explains the first and third rows. Single quotes: "A string enclosed in single quotation marks is a verbatim string. The string is passed to the command exactly as you type it. No substitution is performed." The colon: "PowerShell considers everything between the $ and the : a scope specifier, typically causing the interpretation to fail."

FAQ​

Does $home in lower case work too?​

Yes: $home printed /Users/you. The about_Case-Sensitivity page: "PowerShell is guaranteed to be case-insensitive on all systems for the following areas:", and the first item in its list is "Variable names". Environment variable names are different on a Mac: $env:home printed nothing, and $null -eq $env:home returned True. The about_Environment_Variables page: "Unlike Windows, environment variable names on macOS and Linux are case-sensitive."

Can I use ~ instead of $HOME?​

Where a command reads a path, yes: Resolve-Path ~ returned /Users/you. The Push-Location page describes the home directory as "represented in the command by the tilde symbol (~), which when used on a FileSystem provider drives is equivalent to $HOME." In text, the tilde stays as typed: "~/Documents" and Join-Path ~ 'Documents' both printed ~/Documents.

What does $HOME hold on Windows?​

The about_Automatic_Variables page: "On Windows, this variable uses the value of the "$Env:USERPROFILE" Windows environment variable, typically C:\Users\<UserName>." This guide ran on a Mac, so it shows only the Mac value.

Conclusion​

$HOME printed /Users/you: the full path of the home folder, set by PowerShell. Build paths inside it with Join-Path, write it in double quotes when you put it into text, and keep its value as it is.

Additional Resources​