[Powershell] Finding discrepancy between two files

thanks to Stackoverlfow: https://stackoverflow.com/questions/8799847/compare-two-csv-files-and-find-discrepancies

The code snippet is about comparing two CSV files containing firewall object groups and list down the discrepancy. the code snippet can be used to out-file to a text.

[System.Collections.ArrayList]$base = Get-Content "C:\Temp\reference_ip.csv"
[System.Collections.ArrayList]$diff = Get-Content "C:\Temp\difference_ip.csv"
$notmatching = @()

foreach ($ip in $base) {
    if (!$diff.Contains($ip)) {
        $notmatching += $ip

Write-Host "Not Matches : "
foreach ($value in $notmatching) {
    $message += $value + [Environment]::NewLine
Write-Host $message

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s