Public/Email/Get-SPFRecord.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Get-SPFRecord {

    <#
    .SYNOPSIS
    Gets SPF records for the requested domain(s).
 
    .DESCRIPTION
    Gets SPF records for the requested domain(s).
     
    .PARAMETER Domain
     The domain(s) to get the SPF records of.
     
    .EXAMPLE
    Get-SPFRecord IntegrisIt.com,Microsoft.com
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [STRING[]]$Domain
    )

    $Results = @()

    $TotalCount = $Domain.Count
    $CurrentCount = 0

    FOREACH ($Entry in $Domain) { 
           
        Write-IntegrisProgressBar -TotalCount $TotalCount -CurrentCount $CurrentCount -Activity "Getting SPF Records" -Status "Getting SPF Record for [$Entry]" -ID 20918232 
        $CurrentCount++ 

        $SPFRecord = (Resolve-DNSName -Type TXT -Name $Entry -ErrorAction SilentlyContinue | Where-Object { $_.Strings -like "*v=spf1*" } )

        IF ($null -eq $SPFRecord) {
            $Results += [PSCustomObject]@{
                PSTypeName = 'IntegrisPowerShell.DNSRecord'
                Domain = $Entry
                Name = $null
                Type = "SPF"
                Purpose = "SPF"            
                Value = "[Missing]"
                Preference = $null
            }   
        }
        ELSE {
            FOREACH ($Item in $SPFRecord) {
                $Results += [PSCustomObject]@{
                    PSTypeName = 'IntegrisPowerShell.DNSRecord'
                    Domain = $Entry
                    Name = $Item.Name
                    Type = $Item.Type
                    Purpose = "SPF"          
                    Value = $Item.Strings -Join ""
                    Preference = ""
                }
            }
        }
    }

    Write-IntegrisLogFile $Results
    
    Write-Progress -ID 20918232 -Completed -Activity "Getting SPF Records"
    RETURN $Results
}