Skip to content

Instantly share code, notes, and snippets.

@ThioJoe
Last active October 23, 2024 15:05
Show Gist options
  • Save ThioJoe/461f713370e9e3f5a1d2206cf1a290f3 to your computer and use it in GitHub Desktop.
Save ThioJoe/461f713370e9e3f5a1d2206cf1a290f3 to your computer and use it in GitHub Desktop.
This PowerShell script finds file extensions that are not shown even when Windows is set to show extensions, then outputs the results to a csv file spreadsheet
# This script will search through the Windows Registry to find file extensions that are not shown even when the "Hide extensions for known file types" option is disabled.
# It does this by looking for file types with the NeverShowExt property set, as well as any CLSID references associated with the file types.
# Author: ThioJoe
# Updated: 9/4/2024 (First Version)
#
# How to Use:
# 1. Open PowerShell and navigate to the path containing this script using the 'cd' command.
# 2. Run the following command to allow running scripts for the current session:
# Set-ExecutionPolicy -ExecutionPolicy unrestricted -Scope Process
# 3. Without closing the PowerShell window, run the script by typing the name of the script file starting with .\ for example:
# .\GetSuperHiddenExtensions.ps1
# Arrays to store file types and CLSIDs with NeverShowExt property
$neverShowExtTypes = @()
$neverShowExtCLSIDs = @()
# Function to get the file extension for a given file type
function Get-FileExtension($fileType) {
$extensions = Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT" |
Where-Object { $_.GetValue("") -eq $fileType } |
Select-Object -ExpandProperty PSChildName
return $extensions
}
# Function to search for NeverShowExt in CLSID
function Search-CLSIDForNeverShowExt {
Write-Host "Searching through HKEY_CLASSES_ROOT\CLSID for NeverShowExt..." -ForegroundColor Green
$clsidPath = "Registry::HKEY_CLASSES_ROOT\CLSID"
Get-ChildItem -Path $clsidPath | ForEach-Object {
$key = $_
$properties = $key.GetValueNames()
if ($properties -contains "NeverShowExt") {
$clsid = $key.PSChildName
$friendlyName = $key.GetValue("") # Get the (Default) value
Write-Host "Found NeverShowExt property for CLSID $clsid" -ForegroundColor Yellow
$script:neverShowExtCLSIDs += [PSCustomObject]@{
CLSID = $clsid
FriendlyName = $friendlyName
}
}
}
}
# Function to search main HKEY_CLASSES_ROOT
function Search-HKCRForNeverShowExt {
Write-Host "Searching through HKEY_CLASSES_ROOT for NeverShowExt and CLSID references..." -ForegroundColor Green
Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT" | ForEach-Object {
$key = $_
$properties = $key.GetValueNames()
if ($properties -contains "NeverShowExt") {
$fileType = $key.PSChildName
$friendlyName = $key.GetValue("") # Get the (Default) value
Write-Host "Found NeverShowExt property for $fileType" -ForegroundColor Yellow
$script:neverShowExtTypes += [PSCustomObject]@{
FileType = $fileType
FriendlyName = $friendlyName
Extensions = (Get-FileExtension $fileType) -join ', '
CLSID = $null
}
}
# Check for CLSID references
$defaultValue = $null
$defaultValue = $key.GetValue("")
if ($defaultValue) {
# The default value will look like: CLSID\{9E56BE61-C50F-11CF-9A2C-00A0C90A90CE} , so need to just get after CLSID\
$clsidValue = $defaultValue -replace '.*CLSID\\', ''
$match = $null
if ($clsidValue -and ($match = $script:neverShowExtCLSIDs | Where-Object { $_.CLSID -eq $clsidValue })) {
$friendlyName = $match.FriendlyName
Write-Host "Found CLSID reference for $($key.PSChildName)" -ForegroundColor Magenta
$extensions = $null
$extensions = (Get-FileExtension $key.PSChildName) -join ', '
if (-not $extensions -and $key.PSChildName.StartsWith('.')) {
$extensions = $key.PSChildName
}
$script:neverShowExtTypes += [PSCustomObject]@{
FileType = $key.PSChildName
FriendlyName = $match.FriendlyName
Extensions = $extensions
CLSID = $clsidValue
}
}
}
}
}
# Main execution
Search-CLSIDForNeverShowExt
Search-HKCRForNeverShowExt
Write-Host "Registry search completed. Preparing output..." -ForegroundColor Green
# Prepare CSV output
$outputPath = "NeverShowExtTypes.csv"
$neverShowExtTypes | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Script completed. Results have been saved to $outputPath" -ForegroundColor Green
Write-Host "Found $($neverShowExtTypes.Count) file types with NeverShowExt property or associated CLSID." -ForegroundColor Green
# Display a preview of the CSV content
Write-Host "`nPreview of CSV content:" -ForegroundColor Cyan
Import-Csv $outputPath | Select-Object -First 5 | Format-Table -AutoSize
@nexowite
Copy link

cool

@NegativeZDevelopers
Copy link

The best user that ever lived.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment