# original pastebin link: https://pastebin.com/w1F15Ptf
# related father link: http://www.reddit.com/r/PowerShell/comments/qvk0d/powershell_fork/
#Hash tables to store results of previous MX checks
$positiveMX = @{}
$negativeMX = @{}
#Adding this just so you have some visual for how far along you are. It will slow it down slightly, so if you're
#purely worried about speed (or not running it interactively), remove this and the 4 $count lines in the loop
$count = 0
#Prep the CSV with headers
"domain,address" | set-content c:\temp\log.txt
#Read the file. Using pipelining to avoid storing the entire thing in memory
get-content "C:\temp\email.txt" | foreach {
$count++
if ($count%500 -eq 0) {
write-host $count -foregroundcolor black -backgroundcolor white
}
$domain= $_.split("@")[1]
#If the MX record passed the test previously, go ahead and pass it through for writing
if ($positiveMX.ContainsKey($domain)) {
"$domain,$_"
#Else, check to see if we found it before but disliked it, and if so do nothing
} elseif ($negativeMX.ContainsKey($domain)) {
#Else, haven't seen it before, need to do an MX Lookup
} else {
#Note that I changed this from '*yahoo.com' to '*yahoo*', since I tried using yahoo.com to test, and that ended with yahoodns.net.
#If you know for sure that you want *yahoo.com, change it back
$mx = nslookup -type=mx $domain | where {$_ -like '*yahoo*'}
#Found it, adding it to the positive list and passing through for writing
if($mx){
"$domain,$_"
$positiveMX.Add($domain,"")
#Didn't find it, adding it to the bad list
} else {
$negativeMX.Add($domain,"")
}
}
} | add-content c:\temp\log.txt
Comments
0 B
|👍
/👎