getfolderpath & Program Data


I have been successfully using [environment]::getfolderpath("ProgramFiles") to get the path to program Files, but now I have a need to also access Program Data, and it looks from this enumeration like ProgramData is not available with this method. Is that true, or am I missing something here?


The quickest way is to use $env:ProgramData as BenH already pointed out in your question comments.

Using the .net Specialfolder, you would have needed to use the CommonApplicationData

Instead of using a string though such as your initial example:


I’d suggest using the enumeration as you will get the possible enumeration values directly into the intellisense while developping.

Finally, because you knew the path you were looking for but not the corresponding variable, you could have listed them all neatly using something like:

Using that snippet, you could have determined that c:\programdata was a special folder path belonging to CommonApplicationData.

The enumeration can still be handy if a specified folder is not in the $env scope (example: My documents special folder).


getfolderpath & Program Data by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply