[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$FirstArchive, [Parameter(Mandatory = $true)] [string]$SecondArchive ) $ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.IO.Compression.FileSystem foreach ($path in @($FirstArchive, $SecondArchive)) { if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "Архив не найден: $path" } } function Get-EntryHash([System.IO.Compression.ZipArchiveEntry]$Entry) { $sha = [System.Security.Cryptography.SHA256]::Create() try { $stream = $Entry.Open() try { $bytes = $sha.ComputeHash($stream) return ([BitConverter]::ToString($bytes)).Replace('-', '').ToLowerInvariant() } finally { $stream.Dispose() } } finally { $sha.Dispose() } } function Get-ZipEntries([string]$Path) { $map = @{} $zip = [IO.Compression.ZipFile]::OpenRead($Path) try { foreach ($entry in $zip.Entries) { if ($entry.Name -eq '') { continue } $name = $entry.FullName.Replace('\', '/') $map[$name] = $entry } $result = @{} foreach ($key in $map.Keys) { $result[$key] = Get-EntryHash ($map[$key]) } return $result } finally { $zip.Dispose() } } $first = Get-ZipEntries (Resolve-Path -LiteralPath $FirstArchive).Path $second = Get-ZipEntries (Resolve-Path -LiteralPath $SecondArchive).Path $onlyFirst = @($first.Keys | Where-Object { -not $second.ContainsKey($_) } | Sort-Object) $onlySecond = @($second.Keys | Where-Object { -not $first.ContainsKey($_) } | Sort-Object) $changed = @($first.Keys | Where-Object { $second.ContainsKey($_) -and $first[$_] -ne $second[$_] } | Sort-Object) function Show-List([string]$Title, [string[]]$Names) { if ($Names.Count -eq 0) { return } "$Title`: $($Names.Count)" foreach ($name in $Names) { " $name" } } Show-List 'Только в первом' $onlyFirst Show-List 'Только во втором' $onlySecond Show-List 'Изменены' $changed if ($onlyFirst.Count -eq 0 -and $onlySecond.Count -eq 0 -and $changed.Count -eq 0) { "Архивы совпадают по содержимому." exit 0 } "Архивы различаются." exit 1