Public/Utilities/Analyze-SpamfilterDomains.ps1

function Analyze-SpamfilterDomains {
    param (
        [Parameter(ValueFromPipeline)]
        [string]$Domain
    )

    begin {
        $UsingSpamfilterIO = 0
        $NotUsingSpamfilterIO = 0
    }

    process {
        $MXRecord = Resolve-DnsName -Name $Domain -Type mx -ErrorAction SilentlyContinue | Where-Object Type -eq 'MX' | Sort-Object Preference | Select-Object -First 1
        if ($MXRecord.NameExchange -like '*.spamfilter.io') {
            # Write-Host "$Domain is using Spamfilter.io" -ForegroundColor Green
            # All good
            $UsingSpamfilterIO++
        }
        else {
            Write-Host "$Domain is NOT using Spamfilter.io - Current MX: $($MXRecord.NameExchange)" -ForegroundColor Red
            $NotUsingSpamfilterIO++
        }
    }

    end {
        # Print summary if more than one domain was analyzed
        if ($UsingSpamfilterIO+$NotUsingSpamfilterIO -le 1) {
            return
        }

        Write-Host "Using Spamfilter.io: $UsingSpamfilterIO" -ForegroundColor Green
        Write-Host "Not using Spamfilter.io: $NotUsingSpamfilterIO" -ForegroundColor Red
        Write-Host "Total: $($UsingSpamfilterIO + $NotUsingSpamfilterIO)" -ForegroundColor Yellow
    }
}