Public/Utilities/Confirm-M365Records.ps1

function Confirm-M365Records () {
    Param(
        [Parameter(Mandatory)]
        [string]$DomainName
    )

    $SPFRecord = (Resolve-DnsName -Name $DomainName -Type TXT -ErrorAction SilentlyContinue).Strings | Where-Object { $_ -like 'v=spf1*' }
    $AutoDiscoverRecord = (Resolve-DnsName -Name "autodiscover.$($DomainName)" -Type CNAME -ErrorAction SilentlyContinue).NameHost
    $MXRecord = (Resolve-DnsName -Name $DomainName -Type MX -ErrorAction SilentlyContinue).NameExchange
    $EnterpriseRegistrationRecord = (Resolve-DnsName -Name "enterpriseregistration.$($DomainName)" -Type CNAME -ErrorAction SilentlyContinue).NameHost
    $EnterpriseEnrollmentRecord = (Resolve-DnsName -Name "enterpriseenrollment.$($DomainName)" -Type CNAME -ErrorAction SilentlyContinue).NameHost

    if ($SPFRecord) {
        if($SPFRecord -like "*include:spf.protection.outlook.com*") {
            Write-Host "SPF: $($SPFRecord)" -ForegroundColor Green
        }
        else {
            Write-Host "SPF: $($SPFRecord)" -ForegroundColor Yellow
        }
    }
    else {
        Write-Host "SPF: No SPF record found." -ForegroundColor Red
    }
    if ($AutoDiscoverRecord) {
        if($AutoDiscoverRecord -eq "autodiscover.outlook.com") {
            Write-Host "AutoDiscover: $($AutoDiscoverRecord)" -ForegroundColor Green
        }
        else {
            Write-Host "AutoDiscover: $($AutoDiscoverRecord)" -ForegroundColor Yellow
        }
    }
    else {
        Write-Host "AutoDiscover: No AutoDiscover record found." -ForegroundColor Red
    }
    if ($MXRecord) {
        if($MXRecord -eq "mx.spamfilter.io") {
            Write-Host "MX: $($MXRecord)" -ForegroundColor Green
        }
        else {
            Write-Host "MX: $($MXRecord)" -ForegroundColor Yellow
        }
    }
    else {
        Write-Host "MX: No MX record found." -ForegroundColor Red
    }
    if ($EnterpriseRegistrationRecord) {
        if($EnterpriseRegistrationRecord -eq "enterpriseregistration.windows.net") {
            Write-Host "EnterpriseRegistration: $($EnterpriseRegistrationRecord)" -ForegroundColor Green
        }
        else {
            Write-Host "EnterpriseRegistration: $($EnterpriseRegistrationRecord)" -ForegroundColor Yellow
        }
    }
    else {
        Write-Host "EnterpriseRegistration: No EnterpriseRegistration record found." -ForegroundColor Red
    }
    if ($EnterpriseEnrollmentRecord) {
        if($EnterpriseEnrollmentRecord -eq "enterpriseenrollment.manage.microsoft.com") {
            Write-Host "EnterpriseEnrollment: $($EnterpriseEnrollmentRecord)" -ForegroundColor Green
        }
        else {
            Write-Host "EnterpriseEnrollment: $($EnterpriseEnrollmentRecord)" -ForegroundColor Yellow
        }
    }
    else {
        Write-Host "EnterpriseEnrollment: No EnterpriseEnrollment record found." -ForegroundColor Red
    }
}