#PSTip Preview PowerShell script files in Windows Explorer Preview Pane

The Windows Explorer Preview Pane can display the contents of text files, graphics, and other file types without having to use external software.

To add new file types to preview, such as PowerShell scripts, run the following command:

PS> Set-ItemProperty Registry::HKEY_CLASSES_ROOT\.ps1 -Name PerceivedType -Value text

Here’s how it looks in regedit.exe after the value has been added.

Now navigate to your scripts folder and select a script file. If the preview pane is open and you don’t see the script content, turn preview off and then on (you can use the ALT+P shortcut twice) to force Explorer to read the Registry value. Now you should see its content displayed:

To enable preview for multiple extensions:

PS> Get-Item Registry::HKEY_CLASSES_ROOT\* -Include .ps1,.psm1,.psd1 | Set-ItemProperty -Name PerceivedType -Value text

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts