Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IKnownFolderManager interface in PowerShell

Tags:

powershell

I am writing a PS script that needs to 'convert' a given path, such as %UserProfile%\Pictures into its full path and return any special folder values that may exist, converting true paths, to GUIDs and SpecialFolder Names.

From the MSDN shell reference for KNOWNFOLDERID (Can't post more than 2 links ATM. Grrr), I am assuming every "Special Folder" has various properties such as GUID, Display Name, Default Path etc.

I've come across IKnownFolderManager interface on MSDN and its methods; look like the sort of thing I am after. The trouble is, I cannot find any PowerShell examples of how one might use this "shell interface" and was wondering if anyone would be prepared to offer up an example.

Apologies for not sharing what I have tried so far, but it is no more than this "Hey, Scripting Guy" post that is about as far as I have got.

Edit:

I am most of the way through a script to create the XML-based file, behind Windows Libraries, to allow me to set it up the way I want, removing many of the GUI based restrictions imposed by MS. The XML file will be created by a "Logon" PowerShell script that reads certain variables from an HKCU key. The registry values themselves are created by GPP registry settings. I want an admin to be able to set a registry property and its variable via GPP to say "Pictures" %UserProfile%/Pictures. For the XML file to use this path, the PS script has to expand %UserProfile%. No problem there. Also the XML file "understands" Special Folders, but it uses the special folder's GUID.

There is a reg key (HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions) that contains the folder name and GUID that I can use to covert the folder name to GUID, but the problem is, this registry entry uses the "Legacy Display Name" (My Pictures) as opposed to the true path (Pictures), according to KNOWNFOLDERID. What I am actually asking, is if there is a way of "enumerating" the constants shown KNOWNFOLDERID page. I understand these are just constants, but can the same "table" be pulled out of the system somehow. I can then work out a way to achieve the "Lookup" / "Conversion" my script needs.

like image 795
woter324 Avatar asked Dec 07 '25 04:12

woter324


1 Answers

I think you can get what you are looking for from the following:

[environment]::getfolderpath("mydocuments")  
[environment]::getfolderpath("mypictures")  
[environment]::getfolderpath("userprofile")  

and others, ie:

PS U:\> [environment]::getfolderpath("mypictures")
C:\Users\raf\Pictures
like image 160
Raf Avatar answered Dec 08 '25 19:12

Raf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!