Welcome on my blog

We use cookies to ensure you get the best experience on our website.

PowerShell – Wyszukaj różnice w katalogach

Autor: chmajster 19.06.2023
param(
    [string]$Path1 = 'C:\Users\Chris\Downloads\tm\znanitrenerzy\',
    [string]$Path2 = 'C:\Users\Chris\Downloads\tm\znanitrenerzy_backu\'
)

function Compare-Directories {
    param(
        [string]$Path1,
        [string]$Path2
    )

    $files1 = Get-ChildItem -Path $Path1 -Recurse -File
    $files2 = Get-ChildItem -Path $Path2 -Recurse -File

    $diff1 = Compare-Object -ReferenceObject $files1 -DifferenceObject $files2 -Property Name, Length, LastWriteTime -PassThru | Where-Object { $_.SideIndicator -eq '=>' }
    $diff2 = Compare-Object -ReferenceObject $files2 -DifferenceObject $files1 -Property Name, Length, LastWriteTime -PassThru | Where-Object { $_.SideIndicator -eq '=>' }

    $differences = @()
    $differences += $diff1
    $differences += $diff2

    if ($differences.Count -gt 0) {
        Write-Host "Found $($differences.Count) differences:"
        $table = $differences | Select-Object Name, @{Name="Size"; Expression={"{0:N2} MB" -f ($_.Length / 1KB)}}, LastWriteTime, @{Name="Path"; Expression={$_.FullName}}
        $table | Format-Table -AutoSize
    }
    else {
        Write-Host "No differences found between the directories."
    }
}

Compare-Directories -Path1 $Path1 -Path2 $Path2
Dodaj komentarz

Search
Categories
O Blogu

Cześć Podróżniku!

Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.

Buy me A coffee
[Empty]

Wszelkie prawa zastrzeżone