Last active
October 4, 2023 09:04
-
-
Save OlinB/62c93d8803527846f8c649b0c5d0f146 to your computer and use it in GitHub Desktop.
Powershell recursive folder comparaison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# Goes in Documents\PowerShell\profile.ps1 #> | |
<# usage: CompareDir path\to\folder\1 path\to\folder\2 #> | |
function GetFiles($path, [string[]]$excludedFiles) | |
{ | |
foreach ($item in Get-ChildItem $path) | |
{ | |
if ($excludedFiles | Where {$item -like $_}) { continue } | |
if( (Get-Item $item.FullName) -is [System.IO.DirectoryInfo]){ | |
$('['+$item.Name+']') | |
}else{ | |
$($item.Name) | |
} | |
if (Test-Path $item.FullName -PathType Container) | |
{ | |
GetFiles $item.FullName $excludedFiles | |
} | |
} | |
} | |
function CompareDir($folder1, $folder2) | |
{ | |
$env1 = GetFiles -path $folder1 | |
$env2 = GetFiles -path $folder2 | |
Compare-Object -DifferenceObject $env1 -ReferenceObject $env2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment