How To Preview PowerShell Files in Windows Explorer

4

Windows Explorer, now called File Explorer in Windows 10, has a preview feature pane that, when enabled, displays the content of the selected file without opening them. It works pretty well for the types of files that are registered in the system, such as PDF files, Word documents, Excel spreadsheet, or even MP3 music files. But oddly enough, it doesn’t work for PowerShell files

image 18 600x269 - How To Preview PowerShell Files in Windows Explorer

There are three types of PowerShell files, .ps1, .psm1, and .psd1. And unfortunately, none of them are properly registered in Windows out of the box. Since they are basically the text-based files, we can manually set them up so Windows Explorer can use Notepad to preview them.

Open Registry Editor, and go to the following location:

HKEY_CURRENT_USER\Software\Classes

Right-click Classes key and click New > Key.

image 21 600x375 - How To Preview PowerShell Files in Windows Explorer

Name it .ps1 and then add a new String Value called .ps1 and set its value to “Text”

image 22 600x327 - How To Preview PowerShell Files in Windows Explorer

Repeat the same steps for other two types of PowerShell file. Or, you can simply run the following PowerShell script to add them all at once.

$path = 'HKCU:\Software\Classes\.ps1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path
}

$path = 'HKCU:\Software\Classes\.psd1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path
}

$path = 'HKCU:\Software\Classes\.psm1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path
}

Get-Item HKCU:\Software\Classes\* -Include .ps1,.psm1 ,.psd1 |
Set-ItemProperty -Name PerceivedType -Value text

If Preview Pane in Windows Explorer isn’t your preferred method for previewing the files, how about this QuickLook app?

SHARE

4 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here