Skip to content

Instantly share code, notes, and snippets.

@OlinB
Last active October 4, 2023 09:04
Show Gist options
  • Save OlinB/62c93d8803527846f8c649b0c5d0f146 to your computer and use it in GitHub Desktop.
Save OlinB/62c93d8803527846f8c649b0c5d0f146 to your computer and use it in GitHub Desktop.
Powershell recursive folder comparaison
<# 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