Get all Exchange SMTP addresses and export to CSV
Heyo and buy clomid with mastercard Happy New Year!
A new year brings even more acquisitions and as such, the ongoing desire to automate as many of these tasks as possible. Our latest one is nice because they are a decent sized company, running Microsoft products, namely Exchange. As with nearly all acquisitions, these companies have multiple aliases for a single mailbox. This particular one has roughly 6 different domains/aliases for each user. Thus, I created this script.
This script will pull all of the mailboxes from the Exchange org, select all the SMTP addresses and export all of the data to a spreadsheet. Also, we break up all of the SMTP addresses with a semicolon so that we can later import those addresses to Exchange. Simply put, my import process uses a semicolon to decipher different addresses, so the export process should work upon that base.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
function Get-SMTPAddresses { $Mailboxes = Get-Mailbox -ResultSize unlimited $Results = @() foreach($Mailbox in $Mailboxes) { $Output = new-object PSObject $Name = $Mailbox.Name $EmailAddresses = $Mailbox | select Name -expand emailaddresses | Select SmtpAddress $SMTPAddress = $null; $Output | add-member -membertype NoteProperty -name "Name" -value $Name -force foreach($EmailAddress in $EmailAddresses) { if($EmailAddress.SmtpAddress) { $SMTPAddress += $EmailAddress.SmtpAddress + ";"; } } $Output | add-member -membertype NoteProperty -name "Email Addresses" -value $SMTPAddress -force $Results += $Output } $Results | export-csv "C:\SMTPAddresses.csv" -notypeinformation } |
Thanks for reading!