In this post, we introduce a PowerShell script that identifies and lists duplicate files in a specified directory. This script is useful for cleaning up unnecessary duplicates and saving disk space.
powershell
$targetDirectory = 'C:\FilesToScan'
$files = Get-ChildItem -Path $targetDirectory -File
$duplicateGroups = $files | Group-Object Name, Length | Where-Object { $_.Count -gt 1 }
if ($duplicateGroups.Count -gt 0) {
Write-Host "Duplicate files found:"
foreach ($group in $duplicateGroups) {
Write-Host "Group of duplicates:"
$group.Group | ForEach-Object { Write-Host " - $($_.FullName)" }
}
} else {
Write-Host "No duplicate files found in '$targetDirectory'."
}
Write-Host "Duplicate file search completed for '$targetDirectory'."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
Ready when you are.
Try ServerEngine free for 7 days.