Skip to content

Instantly share code, notes, and snippets.

@Rugby-Ball
Created October 5, 2023 02:59
Show Gist options
  • Save Rugby-Ball/413db069025988d435082430b03b11a9 to your computer and use it in GitHub Desktop.
Save Rugby-Ball/413db069025988d435082430b03b11a9 to your computer and use it in GitHub Desktop.
From an array pulls the SPF, DMARC and DKIM of a domain. for DKIM you need to know the DKIM_Selector or leave it blank to skip pulling the DKIM. #Utility #Inventory #SPF #email #Public #DMARC #DKIM
# dkim-spf-dmarc-inventory.ps1
#Install-Module -name DomainHealthChecker # Only needed if you don't already have the Module installed
import-module -name DomainHealthChecker
$all = @()
# List of the domains to check, and there dkim selector used in the DNS. If you don't have the dkim selector leave blank "".
$urls_check = @( [pscustomobject]@{'domain'="example2.com";'dkim_selector'="t9959"},
[pscustomobject]@{'domain'="example2.com";'dkim_selector'="ps0717"},
[pscustomobject]@{'domain'="google.com";'dkim_selector'=""} #example of a blank dkim_selector
)
$runon = Get-date -Format "MM/dd/yyyy hh:mm tt K"
foreach ($url in $urls_check) {
$all += Invoke-SpfDkimDmarc -Name $url.domain | Select-Object @{N = "Run-On";E = {$runon}},Name, SPFRecord, DMARCRecord, @{n= "DKIM_Selector";e= {$url.dkim_selector} }, @{N = "DKIM_Record";E = { ((Get-DKIMRecord -Name $url.domain -DkimSelector $url.dkim_selector).dkimrecord )} }
}
$all | sort-object name #| clip # replace clip with pbcopy for MacOS - Copies output to clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment