How To Preview PowerShell Files in Windows Explorer

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

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_USERSoftwareClasses

Right-click Classes key and click New > Key.

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

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:SoftwareClasses.ps1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path 
}
$path = 'HKCU:SoftwareClasses.psd1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path 
}
$path = 'HKCU:SoftwareClasses.psm1'
$exists = Test-Path -Path $path
if (!$exists){
$null = New-Item -Path $Path 
}
Get-Item HKCU:SoftwareClasses* -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?

The post How To Preview PowerShell Files in Windows Explorer appeared first on Next of Windows.