Write-Host "Write a path: " $UserInput=Read-Host #Get-FileHash cmdlet to get the hashes $files = Get-ChildItem -Path $UserInput -Recurse | Where-Object -FilterScript { !$_.PSIsContainer } $hashes = $files | ForEach-Object -Process {Get-FileHash -Path $_.FullName -Algorithm SHA256} $duplicates = $hashes | Group-Object -Property Hash | Where-Object -FilterScript {$_.Count -gt 1} foreach($duplicate in $duplicates) { Write-Host -Object "These files share hash : $($duplicate.Group.Path -join ', ')" # delete all duplicates except the first foreach($duplicatePath in ($duplicate.Group.Path | Select-Object -Skip 1)) # { Remove-Item -Path $duplicatePath -Force -WhatIf # } }