A PowerShell binary module for managing duplicate files. Provides cmdlets to detect and remove duplicate files within a directory, and find files with duplicate names across directories.
Import-Module "path/to/DuplicateFileManager.dll"# Build the module
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj -c Release
# Copy to PowerShell modules directory
$modulePath = "$HOME/Documents/PowerShell/Modules/DuplicateFileManager"
New-Item -ItemType Directory -Path $modulePath -Force
Copy-Item src/DuplicateFileManager/bin/Release/net8.0/DuplicateFileManager.dll $modulePath/
Copy-Item build/DuplicateFileManager.psd1 $modulePath/
# Import
Import-Module DuplicateFileManagerDetects and removes duplicate files within a single directory using SHA-256 hash comparison.
Remove-DuplicateFile [-Path] <string> [-TempDirectory <string>] [-Permanent]
[-PartialHashBytes <int>] [-NoColor] [-WhatIf] [-Confirm]
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
-Path |
string | Yes | - | Target directory to scan for duplicates |
-TempDirectory |
string | No | System Temp | Directory to move duplicate files to |
-Permanent |
switch | No | false | Delete files immediately instead of moving |
-PartialHashBytes |
int | No | 65536 | Number of bytes for partial hash calculation |
-NoColor |
switch | No | false | Suppress colored output |
-WhatIf |
switch | No | - | Show what would happen without making changes |
-Confirm |
switch | No | - | Prompt for confirmation before each action |
- Enumerate files in directory (non-recursive)
- Group by file size (eliminate unique sizes)
- Calculate partial hash (first N bytes)
- Group by partial hash (eliminate unique hashes)
- Calculate full SHA-256 hash
- Group by full hash
- Within each group, keep oldest file (by LastWriteTime), mark others as duplicates
# Dry-run to see what would be removed
Remove-DuplicateFile -Path "C:\Photos" -WhatIf
# Move duplicates to specified directory
Remove-DuplicateFile -Path "C:\Photos" -TempDirectory "C:\Temp\Duplicates"
# Permanently delete duplicates with confirmation
Remove-DuplicateFile -Path "C:\Photos" -Permanent -Confirm
# Suppress colored output
Remove-DuplicateFile -Path "C:\Photos" -NoColorFinds files with matching names between two directories.
Find-DuplicateFileName [-ReferencePath] <string> [-DifferencePath] <string>
[-CaseSensitive] [-SingleLine] [-NoColor]
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
-ReferencePath |
string | Yes | - | Source directory for comparison |
-DifferencePath |
string | Yes | - | Target directory to compare against |
-CaseSensitive |
switch | No | false | Enable case-sensitive filename comparison |
-SingleLine |
switch | No | false | Compact single-line output format |
-NoColor |
switch | No | false | Suppress colored output |
Returns FileNameMatch objects with the following properties:
| Property | Type | Description |
|---|---|---|
FileName |
string | The matching file name |
ReferenceFullPath |
string | Full path in reference directory |
DifferenceFullPath |
string | Full path in difference directory |
ReferenceLastWriteTime |
DateTime | Last modified time in reference |
DifferenceLastWriteTime |
DateTime | Last modified time in difference |
ReferenceSize |
long | File size in reference directory |
DifferenceSize |
long | File size in difference directory |
# Find duplicate file names
Find-DuplicateFileName -ReferencePath "C:\Original" -DifferencePath "C:\Backup"
# Case-sensitive comparison
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" -CaseSensitive
# Compact single-line output
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" -SingleLine
# Export results to CSV
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" |
Export-Csv -Path "duplicates.csv" -NoTypeInformation- .NET 8.0 SDK or later
- PowerShell 7.0 or later
# Restore and build
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj
# Build release
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj -c Release