Print Windows PATH with Each Entry on a New Line
In this article
Yes, you can display every folder stored in the Windows PATH environment variable on its own line using either Command Prompt or PowerShell. The commands are built‑in, require no extra software, and work on any supported version of Windows.
What You'll Need
- A Windows PC (any edition that includes Command Prompt and PowerShell)
- Basic familiarity with typing commands
Step‑by‑Step
- Open the appropriate shell.
- For Command Prompt: press Win+R, type
cmd, and press Enter. - For PowerShell: press Win+X and choose Windows PowerShell (or Windows Terminal and select a PowerShell tab).
The steps below are written for the default English language version of Windows; menu names may differ slightly in other locales.
- For Command Prompt: press Win+R, type
- Use a command that splits the PATH string on the semicolon delimiter.
In Command Prompt, type the following and press Enter:
echo %PATH:;=&echo.
This syntax replaces each semicolon (
;) with a line‑break command (&echo.), causing the output to appear one entry per line.In PowerShell, the equivalent command is:
$Env:PATH -split ";" | ForEach-Object { $_ }The
-splitoperator turns the single string into an array, and the pipeline prints each element on its own line. - Verify the output.
Scroll through the list that appears. Each line should be a full directory path, such as
C:\Windows\System32orC:\Program Files\Git\cmd. If you see a single long line with semicolons still present, the command was not entered correctly. - Optional: Save the list to a text file.
For later reference or sharing, you can redirect the output to a file.
- Command Prompt:
echo %PATH:;=&echo. > "%USERPROFILE%\path_list.txt"
- PowerShell:
$Env:PATH -split ";" | Set-Content "$HOME\path_list.txt"
The file
path_list.txtwill be created in your user profile folder and will contain one path per line. - Command Prompt:
- Close the shell.
Type
exitand press Enter, or simply click the close button.
Common Mistakes
- Using the wrong variable syntax. In Command Prompt the variable is
%PATH%; in PowerShell it is$Env:PATH. Mixing the two will produce an empty result. - Forgetting to escape the semicolon in PowerShell. The delimiter must be quoted (
";") or escaped; otherwise PowerShell treats it as a command separator. - Running the Command Prompt command in PowerShell (or vice‑versa). The syntax is shell‑specific, so copy the exact line for the environment you are using.
- Redirecting output without quoting the file path. If the path contains spaces, wrap it in double quotes, otherwise the redirection will fail.
Tips
- Combine the list with
sort(PowerShell) orsort(Command Prompt) to view entries alphabetically:($Env:PATH -split ";") | Sort-Object
- Use
where.exeto test whether a particular executable is found in the PATH:where notepad
- If you need a quick one‑liner that works in both shells, use
cmd /c "echo %PATH:;=&echo."from PowerShell. - To temporarily add a folder for the current session, use
set PATH=%PATH%;C:\MyFolderin Command Prompt or$Env:PATH += ";C:\MyFolder"in PowerShell, then re‑run the split command to see the new entry.
Troubleshooting
If the output is not what you expected, follow these checks in order:
- Confirm the shell. Look at the window title; it will say "Command Prompt" or "PowerShell". If you are in the wrong shell, close it and reopen the correct one.
- Check the variable value. Run
echo %PATH%in Command Prompt orecho $Env:PATHin PowerShell. If the command returns an empty line, the PATH variable may have been cleared or you are using a restricted account. - Ensure the delimiter is a semicolon. The default Windows delimiter is
;. If a custom delimiter was introduced by a third‑party tool, the split command will not work. In that case, replace";"with the actual character. - Update the shell. Some older Windows installations require a restart of the command window after changes to environment variables. Close all open shells and open a new one before re‑running the command.
- Run as administrator. Certain system‑level PATH entries are only visible to elevated processes. Right‑click the shell shortcut and choose "Run as administrator" if you suspect missing entries.
- Inspect for hidden characters. Occasionally a trailing carriage‑return or invisible Unicode character can break the split. Use
Set-Content -Encoding ASCIIwhen saving to a file to strip non‑ASCII characters.
Frequently Asked Questions
Can I view the PATH variable in the graphical System Properties dialog?
Yes. Open the Run dialog (Win+R), type sysdm.cpl, press Enter, go to the "Advanced" tab, click "Environment Variables…", then select "Path" under either "User variables" or "System variables". The dialog shows each entry on a separate line, but it is read‑only.
Why does my PATH contain duplicate entries?
Duplicates often appear after installing software that appends its folder without checking for existing entries. Duplicate paths do not usually cause errors, but they can slow down command lookup. Use the sort -Unique pipeline in PowerShell to filter them.
Is there a way to edit the PATH directly from the command line?
Yes. In Command Prompt you can use setx PATH "%PATH%;C:\NewFolder" /M to add a system‑wide entry, and in PowerShell you can modify $Env:PATH for the current session or use [Environment]::SetEnvironmentVariable() for permanent changes.
Will the commands work on Windows Server editions?
Absolutely. The same environment variable syntax and PowerShell cmdlets exist on Windows Server, so the one‑line split commands function identically.
What if my PATH contains very long entries that wrap in the console window?
Increase the console buffer width: right‑click the title bar, choose "Properties", go to the "Layout" tab, and set a larger "Screen Buffer Size" width. The output will then stay on a single line per entry, making it easier to read.