Untitled
unknown
plain_text
8 months ago
3.4 kB
6
Indexable
$SourceFolders = @(
"\\ServerA\Folder1",
"\\ServerA\Folder2",
"\\ServerA\Folder3",
"\\ServerA\Folder4",
"\\ServerA\Folder5",
"\\ServerA\Folder6",
"\\ServerA\Folder7",
"\\ServerA\Folder8",
"\\ServerA\Folder9",
"\\ServerA\Folder10",
"\\ServerA\Folder11",
"\\ServerA\Folder12",
"\\ServerA\Folder13",
"\\ServerA\Folder14",
"\\ServerA\Folder15",
"\\ServerA\Folder16",
"\\ServerA\Folder17",
"\\ServerA\Folder18",
"\\ServerA\Folder19",
"\\ServerA\Folder20"
)
$DestinationFolders = @(
"\\ServerB\Folder1",
"\\ServerB\Folder2",
"\\ServerB\Folder3",
"\\ServerB\Folder4",
"\\ServerB\Folder5",
"\\ServerB\Folder6",
"\\ServerB\Folder7",
"\\ServerB\Folder8",
"\\ServerB\Folder9",
"\\ServerB\Folder10",
"\\ServerB\Folder11",
"\\ServerB\Folder12",
"\\ServerB\Folder13",
"\\ServerB\Folder14",
"\\ServerB\Folder15",
"\\ServerB\Folder16",
"\\ServerB\Folder17",
"\\ServerB\Folder18",
"\\ServerB\Folder19",
"\\ServerB\Folder20"
)
# Ensure both arrays have the same length
if ($SourceFolders.Count -ne $DestinationFolders.Count) {
Write-Error "The number of source and destination folders must be the same."
exit
}
$OverallDifferences = @()
# Function to compare file names and count
function Compare-FolderContent {
param(
[string]$SourcePath,
[string]$DestinationPath
)
$Differences = @()
# Get all file names (relative paths)
$SourceFiles = Get-ChildItem -Path $SourcePath -Recurse -File | ForEach-Object { $_.FullName.Replace($SourcePath, "") }
$DestinationFiles = Get-ChildItem -Path $DestinationPath -Recurse -File | ForEach-Object { $_.FullName.Replace($DestinationPath, "") }
$OnlyInSource = Compare-Object -ReferenceObject $SourceFiles -DifferenceObject $DestinationFiles -PassThru | Where-Object { $_.SideIndicator -eq "<=" }
$OnlyInDestination = Compare-Object -ReferenceObject $SourceFiles -DifferenceObject $DestinationFiles -PassThru | Where-Object { $_.SideIndicator -eq "=>" }
if ($OnlyInSource.Count -gt 0) {
$Differences += "Files only in source:"
$Differences += $OnlyInSource
}
if ($OnlyInDestination.Count -gt 0) {
$Differences += "Files only in destination:"
$Differences += $OnlyInDestination
}
return $Differences
}
# Loop through folder pairs
for ($i = 0; $i -lt $SourceFolders.Count; $i++) {
Write-Host "Comparing: $($SourceFolders[$i]) <-> $($DestinationFolders[$i])" -ForegroundColor Cyan
$Diffs = Compare-FolderContent -SourcePath $SourceFolders[$i] -DestinationPath $DestinationFolders[$i]
if ($Diffs.Count -eq 0) {
Write-Host "Folders are identical." -ForegroundColor Green
} else {
Write-Host "Differences found:" -ForegroundColor Red
$Diffs | ForEach-Object { Write-Host $_ }
$OverallDifferences += "==== $($SourceFolders[$i]) vs $($DestinationFolders[$i]) ===="
$OverallDifferences += $Diffs
}
}
# Final summary
if ($OverallDifferences.Count -eq 0) {
Write-Host "All folder pairs are identical." -ForegroundColor Green
} else {
Write-Host "Summary of differences:" -ForegroundColor Yellow
$OverallDifferences | ForEach-Object { Write-Host $_ }
}
Editor is loading...
Leave a Comment