Reading Associated File Extensions from Registry (Part 2)

by Mar 19, 2015

All versions

In a previous tip you learned how a one-liner can read multiple registry keys. In part 2, check out this one-liner:

$lookup = Get-ItemProperty Registry::HKCR\.[a-f]?? | 
  Select-Object -Property PSChildName, '(default)', ContentType, PerceivedType |
  Group-Object -Property PSChildName -AsHashTable -AsString

It reads all keys in HKCR that start with a dot, followed by three letters, of which the first letter must be a-f – it reads all file extensions that start with a-f, and are exactly 3 characters wide.

In addition, the results are piped to Group-Object, and the property “PSChildName” is used as key for a lookup table.

PSChildName always returns the registry key name, which in this example is the name of the file extension.

After you run this line, you can now look up any registered file extension:

 
PS> $lookup.'.avi'

PSChildName         (default)           ContentType         PerceivedType      
-----------         ---------           -----------         -------------      
.avi                WMP11.AssocFile.AVI                     video              



PS> $lookup.'.fon'

PSChildName         (default)           ContentType         PerceivedType      
-----------         ---------           -----------         -------------      
.fon                fonfile                                                    
 

Just keep in mind that the line limited file extensions to three letter file extensions that start with a-f. To get all file extensions, use this path instead:

Registry::HKCR\.*

Twitter This Tip! ReTweet this Tip!