#Fase 1, hacer Lista de HASHes $fecha = Get-Date -Format 'yyyy-MM-dd_HH-mm' $Path = read-host "RUTA* ejemplo c:\users\" $HashFile = join-path $PSScriptRoot "$($fecha)_hash.csv" $Count = 0 #contar hashes Get-ChildItem -Path $Path -File -Recurse | ForEach-Object { $Hash = Get-FileHash -Path $_.FullName -Algorithm md5 $Count++ Write-Host "`rConstruyendo lista... $Count hashes" -NoNewline [PSCustomObject]@{ Path = $_.FullName Size = $_.Length SizeMB = [math]::Round($_.Length / 1MB, 2) Hash = $Hash.Hash } } | Export-Csv -Path $HashFile -NoTypeInformation -Encoding UTF8 #Fase 2, comparacion de HASHes $Files = Import-Csv $HashFile $Duplicates = $Files | Group-Object Hash | Where-Object { $_.Count -gt 1 } | ForEach-Object { $_.Group } if ($duplicates.count -gt 0) { $DuplicateFile = join-path $PSScriptRoot "$($fecha)_duplicados.csv" $Duplicates | Export-Csv $DuplicateFile -NoTypeInformation -Encoding UTF8 Write-Host "Duplicados encontrados: $($Duplicates.Count)" -ForegroundColor Green Write-Host "Resultado guardado en: $DuplicateFile" -ForegroundColor Yellow $duplicados_content = Get-Content $DuplicateFile write-output $duplicados_content read-host "Presione cualquier tecla para salir" exit } elseif ($duplicates.count -eq 0) { write-host "no se encontraron duplicados en $path" -ForegroundColor Green read-host "presione una tecla para salir" exit } read-host "presione una tecla para salir"