Distinguish repeated filenames from content-identical files using staged comparisons.

Sheet: 19 of 25 | Platform: Windows 10/11 | Shell: PowerShell 7.x and Windows PowerShell 5.1 (unless marked otherwise) | Editorial review: November 24, 2026

PowerShell cheat sheet index

Examples use the MGU project root and illustrative staging, backup, and download paths. Replace them with existing, approved paths as needed. Unless explicitly marked as a continuation, examples are independent. Read commands before running them; commands that write or modify files can change existing data.

Quick commands

1. Find repeated filenames

Get-ChildItem -LiteralPath 'C:\MGU\library' -Recurse -File |
    Group-Object Name | Where-Object Count -gt 1 |
    Select-Object Name, Count

2. Find candidate duplicates by size

Get-ChildItem -LiteralPath 'C:\MGU\library' -Recurse -File |
    Group-Object Length | Where-Object Count -gt 1 |
    Select-Object Name, Count

3. Hash only files in repeated-size groups

$candidates = Get-ChildItem -LiteralPath 'C:\MGU\library' -Recurse -File |
    Group-Object Length | Where-Object Count -gt 1
$hashes = @($candidates | ForEach-Object { $_.Group | Get-FileHash -Algorithm SHA256 -ErrorAction Stop })

4. Group identical hashes (run after hashing)

$duplicates = @($hashes | Group-Object Hash | Where-Object Count -gt 1)
$duplicates | ForEach-Object { $_.Group | Select-Object Hash, Path }

5. Export duplicate candidates for review (run after grouping)

$duplicates | ForEach-Object { $_.Group } |
    Export-Csv -LiteralPath 'C:\MGU-Staging\duplicate-candidates.csv' -NoTypeInformation -Encoding UTF8

Operational notes

Repeated names such as index.html are normal. Identical hashes are strong evidence of byte-identical content, not proof that either file is redundant in a website hierarchy. Do not automatically delete duplicate candidates; evaluate links, canonical paths, and purpose.

Official documentation