Skip to content

Instantly share code, notes, and snippets.

@poiriersimon
Created January 9, 2019 18:49
Show Gist options
  • Save poiriersimon/03798b58636ee133dd1dc0fd3f2dbdd0 to your computer and use it in GitHub Desktop.
Save poiriersimon/03798b58636ee133dd1dc0fd3f2dbdd0 to your computer and use it in GitHub Desktop.
Check SPF for all accepted domain in Exchange Online
$AcceptedDomains=Get-AcceptedDomain |where {$_.DomainName -notlike "*.mail.onmicrosoft.com"}
#A better approach would be to validate if the domain is user in a primary email address
$DomainWithoutSPF = @()
foreach($AcceptedDomain in $AcceptedDomains){
$DNS = Resolve-DnsName -Type TXT -Name $AcceptedDomain.DomainName |where{$_.Strings -like "*v=spf1*"}
if($DNS.strings -like "*include:spf.protection.outlook.com*"){Return
}elseif($DNS.strings -like "*include:*"){
foreach($include in $($dns.Strings.split(" ")| where {$_ -like "include:*"})){
$tDns = Resolve-DnsName -Type TXT -Name $($include.split(":")[-1])
if($tDNS.strings -like "*include:spf.protection.outlook.com*"){Return}
}
}
$DomainWithoutSPF += $AcceptedDomain.DomainName
}
$DomainWithoutSPF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment