Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Finding bad e-mail addresses

$
0
0

I am in a large orginization of over 17000 mailboxes and have been tasked with finding a very large number of accounts that have bad -email addresses. Some have an @ at the start, some have a space or two ... I found one script called fix-alias.ps1 but all that would do is look for once thing wrong like..search for "@" and replace with "_" so I've been trying to find a way to find all of the bad primary and secondary address' in the organization. Microsoft sent me this script

 
$fil = (Get-DynamicDistributionGroup IS-Security-PZUsers2@my.work.Biz).RecipientFilter

$rec = Get-Recipient -ResultSize unlimited -RecipientPreviewFilter $fil


trap [System.Exception]
                { 
                    
                    Write-host "Error: " + $_.Exception.Message
                    Continue;        

                }

foreach($r in $rec)
{              
                
                $add = $r.EmailAddresses

        $add >> .\Users.csv
}  

The format of the resulting csv was atrocious so I went about trying to find a better way. I thought a two part process. 

1) Get a one liner to get all of the smtp addresses to a csv using this

Get-Mailbox -ResultSize Unlimited |where {$_.database -ilike "US-EX-*"} | Select-Object Display
Name,ServerName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object {$_.PrefixString
 -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv d:\mailbox_alias.csv

2) use a regex to search for a nomatch inside of that file. 

This isnt working for example

import-csv d:\mailbox_alias.csv  | foreach-object{$_.emailaddresses -nomatch "\b[A-Z0-9._%+-]+@
[A-Z0-9.-]+\.[A-Z]{2,4}\b"} | Write-Host

Im not sure if this is the right approach and another thing is all of the emailaddresses are in one column so I dont know if it would work. So as of now I cant get any type or matching 

So basically

How do I search through all of the mailboxes to search for bad smtp primary and secondary addresses and list those bad addresses out so I can work on them?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>