#PSTip Explore all possible -Verb values for registered file extensions

In previous tips we saw how to find possible values of -Verb parameter and how to use it. What about to check all possible -Verb values for all extensions?
First, let’s investigate all registered (associated) extensions in the system. There is a native tool named assoc. As it’s a part of cmd.exe, we have to call it inside command line. If it’s used without a parameter, it will display all associations.

PS> cmd /c assoc | Select-Object -First 10

Let’s test the whole process with the first extension returned. We need to split input line to receive just that extension.

PS> cmd /c assoc | Select-Object -First 1 | ForEach { ($_ -split '=')[0] }

We used Split operator to obtain just the text before the equal sign. Now we’ll use previous tip to see all possible -Verb values.

cmd /c assoc |
Select-Object -First 1 |
ForEach { ($_ -split '=')[0] } |
ForEach { (New-Object System.Diagnostics.ProcessStartInfo -ArgumentList "test$_").Verbs }


We created a new ProcessStartInfo object and passed a dummy file name to it – in this case named test.323. From the object we created, we extracted only its Verbs property. As we don’t need to create an object from the output, it’s sufficient to send the output to Out-GridView cmdlet. But before that, let’s remove double call of ForEach-Object cmdlet.

cmd /c assoc |
Select-Object -First 10 |
ForEach { $ext = ($_ -split '=')[0]; "{0}: {1}" -f $ext, ((New-Object System.Diagnostics.ProcessStartInfo -ArgumentList "test$ext").Verbs -join ', ') }

.323: open
.3g2: AddToPlaylistVLC, Open, PlayWithVLC
.3gp: AddToPlaylistVLC, Open, PlayWithVLC
.3gp2: AddToPlaylistVLC, Open, PlayWithVLC
.3gpp: AddToPlaylistVLC, Open, PlayWithVLC
.5vw: open
.7Z: open, print
.aac: Batch Convert with WavePad Sound Editor, Convert sound file, Edit sound file, Edit with WavePad Sound Editor

We used PowerShell’s format operator (-f) to have output formatted like: ext: Verb1, Verb2, … Now we can remove Select-Object and send all data to the Out-GridView:

cmd /c assoc |
ForEach { $ext = ($_ -split '=')[0]; "{0}: {1}" -f $ext, ((New-Object System.Diagnostics.ProcessStartInfo -ArgumentList "test$ext").Verbs -join ', ') } | Out-GridView -Title 'Verb values for associated extensions'

About the author: David Moravec

I am in IT industry for 15 years, last 10 years working mainly with Microsoft management technologies. I Work in one of the biggest international accounting companies as administrator responsible for System Center Configuration Manager. I like to automate my infrastructure-related tasks with windows PowerShell. Author and speaker for Microsoft Czech Republic. I'm Running my own blog at PowerShell.cz. You can reach me on Twitter at @makovec

Related Posts

%d bloggers like this: