#PSTip How to find path to your Documents folder

It’s pretty easy to find path to your Documents folder with a little help from .NET Framework’s Environment class:

PS> [Environment]::GetFolderPath('MyDocuments')
C:\Users\Administrator\Documents

You can accomplish the same using the identifier name Personal:

PS> [Environment]::GetFolderPath('Personal')
C:\Users\Administrator\Documents

How can you find all valid names? Specify a wrong name, and PowerShell will help you 🙂

PS> [environment]::GetFolderPath('wrongvalue')
Cannot convert argument "folder", with value: "wrongvalue", for "GetFolderPath" to
 type "System.Environment+SpecialFolder": "Cannot convert value "wrongvalue" to type
 "System.Environment+SpecialFolder". Error: "Unable to match the identifier name wrongvalue
 to a valid enumerator name. Specify one of the following enumerator names and try again:
 Desktop, Programs, Personal, MyDocuments, 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""

About the author: Aleksandar Nikolic

Aleksandar is a PowerShell MVP and a co-founder of PowerShell Magazine. He is a frequent speaker at the conferences and participates regularly in IT Pro user groups worldwide. Recently, Aleksandar co-authored the highly respected Administrator’s Guide to Windows PowerShell Remoting. Follow him on Twitter at @alexandair

Related Posts

%d bloggers like this: