0

A customer asked us the somewhat strange question to make an export off ALL the email addresses their company has ever mailed with.

Not the addresses of their own mailboxes, but all external addresses of their customers, suppliers etc. I guess the tracking logs won't suffice, it won't go back that far.

I need a Powershell command to "scan / search" all mailboxes and all email items. For each email item, the sender and receiver address has to be exported to a file. I am aware that is users have deleted emails, these addresses won't show up in the export since the data is not in the email database anymore.

No problem if it has duplicates, I can filter out duplicates later with some tool. Customer uses Exchange 2007.

Dave M
  • 4,514
  • 22
  • 31
  • 30
NLuser
  • 45
  • 1
  • 6

1 Answers1

0

This should work given that you have less than 9999 recipents in the system. If you have more, just increase the ResultSize.

$recip = Get-Recipient -ResultSize 9999 | Select-Object 
alias,DisplayName,EmailAddresses
$output = @()

# Work thorugh each recipient
$recip | ForEach-Object {
    # Work through each Email alias
    $_.EmailAddresses | ForEach-Object {
        # Clean SMTP from the from of the addresses
        $cleaned = $_.TrimStart("smtp:").TrimStart("SMTP:")

        # Check and exclude x500 system addresses
        if ($cleaned -inotmatch "x500:*") {
            $output += $cleaned
        }
    }
}

$output | Out-File addresses.csv -Force
Cory Knutson
  • 1,876
  • 13
  • 20