Finding System Paths

by Apr 21, 2021

Occasionally, your script needs to know the path to the users’ desktop, or to the start menu, etc. These paths can vary, especially when users use OneDrive. To find the current system path, use this line:

 
PS> [Environment]::GetFolderPath('Desktop')
C:\Users\tobia\OneDrive\Desktop  
 

You can use all constants defined in the [System.Environment+SpecialFolder] type:

 
PS> [Enum]::GetNames([System.Environment+SpecialFolder])
Desktop
Programs
MyDocuments
Personal
Favorites
Startup
Recent
SendTo
StartMenu
MyMusic
MyVideos
DesktopDirectory
MyComputer
NetworkShortcuts
Fonts
Templates
CommonStartMenu
CommonPrograms
CommonStartup
CommonDesktopDirectory
ApplicationData
PrinterShortcuts
LocalApplicationData
InternetCache
Cookies
History

CommonApplicationData
Windows
System
ProgramFiles
MyPictures
UserProfile
SystemX86
ProgramFilesX86
CommonProgramFiles
CommonProgramFilesX86
CommonTemplates
CommonDocuments
CommonAdminTools
AdminTools
CommonMusic
CommonPictures
CommonVideos
Resources
LocalizedResources
CommonOemLinks
CDBurning 
 

If you know the path and would like to know if there’s a registered system path for it that you could use, try the opposite and dump all folder constants and their associated paths:

[Enum]::GetNames([System.Environment+SpecialFolder]) |
  ForEach-Object {
    # ...for each, create a new object with the constant, the associated path
    # and the code required to get that path
    [PSCustomObject]@{
        Name = $_
        Path = [Environment]::GetFolderPath($_)
    }
  }

The result looks like this:

 
Name                   Path                                                             
----                   ----                                                             
Desktop                C:\Users\tobia\OneDrive\Desktop                                  
Programs               C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Start Menu\Pr...
MyDocuments            C:\Users\tobia\OneDrive\Dokumente                                
Personal               C:\Users\tobia\OneDrive\Dokumente                                
Favorites              C:\Users\tobia\Favorites                                         
Startup                C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Start Menu\Pr...
Recent                 C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Recent          
SendTo                 C:\Users\tobia\AppData\Roaming\Microsoft\Windows\SendTo          
StartMenu              C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Start Menu      
MyMusic                C:\Users\tobia\Music                                             
MyVideos               C:\Users\tobia\Videos                                            
DesktopDirectory       C:\Users\tobia\OneDrive\Desktop                                  
MyComputer                                                                              
NetworkShortcuts       C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Network Short...
Fonts                  C:\WINDOWS\Fonts                                                 
Templates              C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Templates       
CommonStartMenu        C:\ProgramData\Microsoft\Windows\Start Menu                      
CommonPrograms         C:\ProgramData\Microsoft\Windows\Start Menu\Programs             
CommonStartup          C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup     
CommonDesktopDirectory C:\Users\Public\Desktop                                          
ApplicationData        C:\Users\tobia\AppData\Roaming                                   
PrinterShortcuts       C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Printer Short...
LocalApplicationData   C:\Users\tobia\AppData\Local                                     
InternetCache          C:\Users\tobia\AppData\Local\Microsoft\Windows\INetCache         
Cookies                C:\Users\tobia\AppData\Local\Microsoft\Windows\INetCookies       
History                C:\Users\tobia\AppData\Local\Microsoft\Windows\History           
CommonApplicationData  C:\ProgramData                                                   
Windows                C:\WINDOWS                                                       
System                 C:\WINDOWS\system32                                              
ProgramFiles           C:\Program Files                                                 
MyPictures             C:\Users\tobia\OneDrive\Bilder                                   
UserProfile            C:\Users\tobia                                                   
SystemX86              C:\WINDOWS\SysWOW64                                              
ProgramFilesX86        C:\Program Files (x86)                                           
CommonProgramFiles     C:\Program Files\Common Files                                    
CommonProgramFilesX86  C:\Program Files (x86)\Common Files                              
CommonTemplates        C:\ProgramData\Microsoft\Windows\Templates                       
CommonDocuments        C:\Users\Public\Documents                                        
CommonAdminTools       C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administr...
AdminTools             C:\Users\tobia\AppData\Roaming\Microsoft\Windows\Start Menu\Pr...
CommonMusic            C:\Users\Public\Music                                            
CommonPictures         C:\Users\Public\Pictures                                         
CommonVideos           C:\Users\Public\Videos                                           
Resources              C:\WINDOWS\resources                                             
LocalizedResources                                                                      
CommonOemLinks                                                                          
CDBurning              C:\Users\tobia\AppData\Local\Microsoft\Windows\Burn\Burn   # 
 


Twitter This Tip! ReTweet this Tip!