Using KNOWNFOLDERID or CSIDL in PowerShell

3.1k views Asked by At

Is there a way to use either KNOWNFOLDERID or CSIDL in PowerShell?

I need to be able to access some "known folders" via PowerShell script on a variety of systems. The problem is that those folders' names tend to differ between languages and Environmental Variables list (e.g. $env:something) does not contain folders I am interested accessing in (e.g. C:\Users).

1

There are 1 answers

6
Keith Hill On BEST ANSWER

Use the .NET method System.Environment.GetFolderPath like so:

[Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData)

The MSDN topic on the Environment.SpecialFolder enum shows all the possible special folders you can ask for.