Created
January 9, 2019 18:49
-
-
Save poiriersimon/03798b58636ee133dd1dc0fd3f2dbdd0 to your computer and use it in GitHub Desktop.
Check SPF for all accepted domain in Exchange Online
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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