powershellknown-folders

How can I use powershell to call SHGetKnownFolderPath?


I'm a total noob on windows powershell. How can I use psl to call SHGetKnownFolderPath ? I want to then also call SHSetKnownFolderPath if I dont like some of the values back from Get call.


Solution

  • You can use P/Invoke. Lee Holmes has an example of how to do this from PowerShell here. There's an example of how to use SHGetKnownFolderPoath here.

    Alternatively, you might just be able to use Environment.GetFolderPath:

    PS> [Environment]::GetFolderPath('CommonApplicationData')
    C:\ProgramData
    

    You can get the list of available options by the following:

    PS> [Enum]::GetNames([Environment+SpecialFolder])