Gather SPF Records For Multiple Domain Names

You can use the following script to gather the SPF records for multiple domains.  You just need to populate a TXT file named DomainNames.txt which exists in the same directory.  Below is the PowerShell:


$SPFRecords = @()
$Counter = 0
$myDir = Split-Path -Parent $MyInvocation.MyCommand.Path

$DomainNames = Get-Content $myDir\DomainNames.txt
$SPFOutput = $myDir + "\SPFRecordsResults.csv"

ForEach ($Domain in $DomainNames) {
    $Counter++
    Write-Progress -Activity "Querying SPF Records" -Status "Processing $($Counter) of $($DomainNames.count)" -CurrentOperation $Domain -PercentComplete (($Counter / $DomainNames.count) * 100)

    $SPFRecord = Resolve-DNSName -Name $Domain -Type TXT | Where {$_.Strings -like "*spf1*"}

    If ($SPFRecord -ne $NULL)   {
        ForEach ($SPF in $SPFRecord) {

            $SPFItem = new-object PSObject -Property @{
                Domain = $SPF.Name
                SPFTXTRecord = $SPF | Select -ExpandProperty Strings
            }

            $SPFRecords += $SPFItem
        }
    }
}

$SPFRecords | Select Domain,SPFTXTRecord | Export-CSV $SPFOutput -NoTypeInformation
Write-Host "Check results in" $SPFOutput

Comments

Popular posts from this blog

Assigning Windows 10/11 Enterprise Subscription Activation Licences to Hybrid Azure AD Joined Devices

Power Automate: Get first item in output

De-selectable radio buttons - Power Apps