AutomaShell

  • TwitterTwitter
  • LinkedInLinkedIn
  • RSS FeedRSS Feed
  • Home
  • About
  • Contact
  • Troy
  • January 3, 2014
  • 0

Get all Exchange SMTP addresses and export to CSV

Heyo and 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!

Exchange Server · PowerShell

© Copyright 2012-2018 AutomaShell. Contact me if you have any questions.

  • TwitterTwitter
  • LinkedInLinkedIn
  • RSS FeedRSS Feed
  • Tabs

    • Recent Posts
    • Most Popular
    • Comments
    • Nutanix AOS 5.10 & Prism Central 5.10 releasedNovember 26, 2018
    • Nest VMware ESXi on Nutanix AHVSeptember 18, 2018
    • Nutanix Calm – AWS Setup & Example App DeploymentAugust 15, 2018
    • Nutanix: Add Unprotected VMs to Protection DomainJune 7, 2018
    • Deploy VMware VM’s with PowerCLIOctober 23, 2012
    • Enable Exchange 2010 Online Archive in a mixed environment (Part 1: By OU)December 4, 2012
    • User Termination (Part 2)June 6, 2013
    • Search Active Directory with PowerShell (LDAP)April 29, 2013
    • Rob Duff on:Search Active Directory with PowerShell (LDAP)
    • sean on:Deploy VMware VM’s with PowerCLI
    • Troy on:Deploy VMware VM’s with PowerCLI
    • Niklas Ilves on:Deploy VMware VM’s with PowerCLI
  • Categories

    • AWS
    • Calm
    • Exchange Server
    • General
    • Nutanix
    • PowerCLI
    • PowerShell
    • Uncategorized
    • VMware
    • Windows Server