A lightweight, dependency-free PowerShell tool that inspects magic bytes and container structures to identify actual file types on Windows — just like the Linux
fileutility.
On Linux, developers and sysadmins rely on the file command to determine what a file actually is by analyzing its magic numbers (header signatures) rather than trusting its file extension.
Windows lacks a native, built-in equivalent that detects deep signatures out-of-the-box. WinFile (Get-RealFileType) brings this capability to PowerShell with:
- Zero third-party dependencies (uses pure .NET binary reading).
- In-memory OpenXML/ZIP inspection to tell
.docx,.xlsx,.pptx,.jar, and.apkapart. - In-memory OLE Compound File (CFB) inspection to differentiate legacy
.doc,.xls,.ppt, and.msgfiles. - Support for PowerShell pipeline operations, batch scanning, mismatch detection, and auto-renaming.
- 🎯 Accurate Signature Matching: Inspects raw binary header bytes across 35+ file formats.
- 📦 Deep Container Inspection:
- ZIP / OpenXML: Inspects internal catalog manifests in memory without writing temporary files to disk.
- OLE CFB (Legacy Office): Reads internal UTF-16LE stream directory sectors (
WordDocument,Workbook,PowerPoint Document,__substg1.0_).
- ⚡ Pipeline Friendly: Seamlessly pipes from
Get-ChildItemfor instant multi-file/directory audits. - 🛡️ Security & Spoof Detection: Easily spots disguised executables or malicious files masked with benign extensions (e.g.
invoice.pdf.exeor.exerenamed to.jpg). - 🪶 100% Native: Runs on standard Windows PowerShell 5.1 as well as PowerShell Core 7+.
| Category | Formats Supported |
|---|---|
| Documents | PDF, DOCX, XLSX, PPTX, DOC, XLS, PPT, RTF, MSG, VSD, EPUB, ODF |
| Images | PNG, JPEG / JPG, GIF, BMP, WebP, TIFF, ICO, PSD |
| Audio & Video | MP4, MKV / WebM, AVI, WAV, MP3, FLAC, OGG, WMV / WMA (ASF) |
| Archives & Packages | ZIP, 7z, RAR, GZIP (.gz), BZIP2 (.bz2), XZ, TAR, APK, JAR |
| Executables & Binaries | Windows EXE / DLL (PE/MZ), Linux ELF, Java Class / Mach-O Fat, macOS Mach-O |
| Data & Databases | SQLite 3 (.db / .sqlite), XML / SVG |
- Download
Get-FileType.ps1from this repository. - In PowerShell, allow local script execution if prompted:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
- Load the function via dot-sourcing:
. .\Get-FileType.ps1
Make Get-RealFileType a permanent command in every PowerShell window:
- Create and open your PowerShell user profile:
New-Item -Path $PROFILE -ItemType File -Force notepad $PROFILE
- Paste the entire content of
Get-FileType.ps1into the profile file, save (Ctrl + S), and close Notepad. - Allow local profile execution:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
- Restart your terminal.
Get-RealFileTypeis now globally available!
Get-RealFileType -Path ".\unknown_payload"Output:
File : C:\Users\User\Downloads\unknown_payload
CurrentExt : (none)
DetectedExt : .pdf
Category : Document
Description : PDF Document
HexSignature : 25 50 44 46 2D 31 2E 37
Get-ChildItem -File | Get-RealFileType | Format-Table File, CurrentExt, DetectedExt, Description -AutoSizeFind files whose actual internal type does not match their visible file extension:
Get-ChildItem -File -Recurse | Get-RealFileType | Where-Object {
$_.DetectedExt -notlike "*$($_.CurrentExt)*" -and $_.DetectedExt -ne "Unknown" -and $_.CurrentExt -ne "(none)"
} | Format-Table File, CurrentExt, DetectedExt, Description -AutoSizeSafely rename files that have no extension by appending their true detected extension:
Get-ChildItem -File | Get-RealFileType | Where-Object {
$_.CurrentExt -eq "(none)" -and $_.DetectedExt -notmatch "Unknown|Empty|/"
} | ForEach-Object {
Rename-Item -LiteralPath $_.File -NewName "$($_.File)$($_.DetectedExt)"
Write-Host "Renamed: $($_.File) -> $($_.File)$($_.DetectedExt)" -ForegroundColor Green
}- Header Streaming: Reads the initial 32 bytes of the target file into a managed byte array.
- Hex Pattern Matching: Evaluates the signature against standardized magic byte regex definitions.
- Deep Container Inspection:
- For
50 4B 03 04(ZIP headers), it initializesSystem.IO.Compression.ZipArchivestrictly in memory to read schema paths (word/,xl/,ppt/,AndroidManifest.xml,META-INF/). - For
D0 CF 11 E0 A1 B1 1A E1(OLE CFB headers), it decodes the directory allocation sectors into UTF-16LE strings to look for active stream signatures (WordDocument,Workbook,PowerPoint Document).
- For
- Custom Object Output: Emits structured
PSCustomObjectinstances that directly support PowerShell piping, filtering, and export (Export-Csv,Out-GridView, etc.).
Contributions are welcome! If you'd like to add support for additional file signatures or container types:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/NewSignature) - Commit your Changes (
git commit -m 'Add support for .flac headers') - Push to the Branch (
git push origin feature/NewSignature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.