ThisCalculator

Everyday

Find Special Folder Paths in PowerShell

Updated · Standard formula, shown below

This guide shows you how to get the full paths of Windows special folders—like Desktop, Documents, AppData, and Program Files—directly in PowerShell. You’ll learn the built-in commands, when to use each, and how to turn the result into a usable path for scripts or file operations.

What You’ll Need

  • Windows 10 or Windows 11
  • PowerShell 5.1 or later (comes preinstalled)
  • Basic familiarity with opening a PowerShell window (Start menu → type “PowerShell”)

Step-by-Step

  1. Open PowerShell. Press Win, type powershell, and hit Enter. For most tasks, a regular window is fine; if you need to modify protected folders, run it as Administrator.
  2. Use the .NET method for any known folder. The most reliable way is [Environment]::GetFolderPath(). Type this and press Enter:
    [Environment]::GetFolderPath('Desktop')
    You’ll see something like C:\Users\YourName\Desktop. This works for any folder in the SpecialFolder enum—replace Desktop with names like MyDocuments, ApplicationData, LocalApplicationData, ProgramFiles, CommonProgramFiles, System, UserProfile, and many more. The method is case-insensitive but must match the enum name exactly (e.g., MyDocuments, not Documents).
  3. Get the user profile folder. If you just need the base user directory, use:
    $env:USERPROFILE
    This returns something like C:\Users\YourName. It’s a quick way to build other paths manually, e.g., $env:USERPROFILE\Downloads.
  4. Use the Shell.Application COM object for non-standard folders. Some folders like Downloads, Pictures, or Music aren’t in the .NET enum but can be accessed via the Windows Shell. Run:
    (New-Object -ComObject Shell.Application).NameSpace(5).Self.Path
    The number is the folder’s CSIDL value. Common ones: 5 = My Documents, 2 = Desktop, 3 = Favorites, 4 = Recent, 6 = My Pictures, 8 = My Music, 9 = My Videos, 20 = Downloads. This returns the actual path, e.g., C:\Users\YourName\Downloads.
  5. Find the current working directory. If you need the folder PowerShell is currently in, use:
    Get-Location or $PWD
    This is not a special folder, but it’s often confused with one in scripts.
  6. List all special folders at once. To see every available .NET special folder and its path, loop through the enum:
    [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder]) | ForEach-Object { $path = [Environment]::GetFolderPath($_); if ($path) { "$_ = $path" } }
    This prints a clean list, skipping empty entries.
  7. Use the path in a script. Store the result in a variable and use it normally:
    $docs = [Environment]::GetFolderPath('MyDocuments')
    Get-ChildItem $docs
    This lists files in your Documents folder.

Common Mistakes

  • Using the wrong enum name. [Environment]::GetFolderPath('Documents') fails because the enum value is MyDocuments. Always check the exact name.
  • Forgetting that paths can be null. If a folder hasn’t been created or is not available, GetFolderPath returns an empty string. Always test with if ($path) before using it.
  • Assuming the user profile is always C:\Users\Username. It can be on a different drive or have a custom name. Use $env:USERPROFILE instead of hardcoding.
  • Mixing up CSIDL numbers. The Shell.Application numbers are not the same as the .NET enum values. Double-check the number you’re using.
  • Using ~ or relative paths. PowerShell does not expand ~ to the home directory in all contexts. Use $env:USERPROFILE or Resolve-Path.

Tips

  • Prefer .NET over COM. The [Environment]::GetFolderPath() method is faster, more reliable, and works in PowerShell Core on Windows as well.
  • For Downloads, use the known folder API if needed. The .NET method doesn’t include Downloads, but you can use the Shell.Application with CSIDL 20 as shown above. Alternatively, in PowerShell 5.1 you can use [Environment]::GetFolderPath('UserProfile') + '\Downloads'—this works because Downloads is always a subfolder of the user profile on default installations.
  • Create a function for repeated use. Add this to your profile:
    function Get-SpecialFolder($name) { [Environment]::GetFolderPath($name) }
  • Remember that paths are case-insensitive in Windows. You can use $docs and $DOCS interchangeably.
  • Use Join-Path to build paths safely. Instead of string concatenation, use Join-Path $docs 'subfolder' to avoid missing backslashes.

Troubleshooting

  • “Cannot find an overload for GetFolderPath” error. This usually means you’re using a string that isn’t a valid enum name. Check the spelling and try the exact name from the enum list (e.g., MyDocuments instead of Documents).
  • Path comes back empty. The folder may not exist or is not defined for the current user. For example, CommonAdminTools might be empty on some systems. Test with if ([Environment]::GetFolderPath('CommonAdminTools')) { ... }.
  • The COM object returns nothing. Ensure the CSIDL number is correct. Some numbers require the folder to exist. Try a different number or use the .NET method for that folder.
  • PowerShell says “New-Object: COM object type was not found.” This happens in PowerShell Core on non-Windows platforms. The Shell.Application COM object is Windows-only. Use .NET methods instead, which work on Windows PowerShell and PowerShell 7 on Windows.
  • You get a path but it’s wrong (e.g., C:\Windows\System32). You might be running PowerShell in a different context (like an elevated prompt) where the user profile is different. Check with whoami and $env:USERPROFILE to see which user you are.

Frequently Asked Questions

How do I get the path to the Downloads folder?

Use (New-Object -ComObject Shell.Application).NameSpace(20).Self.Path or simply Join-Path $env:USERPROFILE 'Downloads' if the folder is in its default location.

Can I use these paths in batch files or CMD?

Yes, but the syntax differs. In CMD, use %USERPROFILE% for the user profile, but there’s no direct equivalent for all special folders. You can call PowerShell from a batch file: for /f "delims=" %%i in ('powershell -Command "[Environment]::GetFolderPath('Desktop')"') do set DESKTOP=%%i.

Why does [Environment]::GetFolderPath(‘Documents’) fail?

Because the enum value is MyDocuments, not Documents. The .NET enum uses legacy names. Check the full list by running the loop in Step 6.

Do these paths work in PowerShell 7 (Core) on Windows?

Yes, [Environment]::GetFolderPath() works in PowerShell 7 on Windows. The COM object also works, but it’s Windows-only. On Linux or macOS, neither works; you’ll need to use environment variables like $HOME.

How do I get the Program Files folder?

Use [Environment]::GetFolderPath('ProgramFiles') for the 64-bit folder (usually C:\Program Files) and [Environment]::GetFolderPath('ProgramFilesX86') for the 32-bit folder (usually C:\Program Files (x86)).

Can I set a special folder path?

You can change the actual location through Windows settings (right-click the folder → Properties → Location), but you cannot set it via PowerShell directly. The GetFolderPath method only reads the current location.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.