Link to home
Start Free TrialLog in
Avatar of Alexandre Michel
Alexandre MichelFlag for Australia

asked on

How can I clean smtp addresses aliases exported from Office 365

Hi Experts

I am planning for a merge of 3 different Office 365 tenancies into one.
I am trying to get a clean list of
  • Mailboxes
  • Main email address
  • Alias emails address(es) if any

All the powershell scripts I could find would give the alias email addresses as follow

SPO:SPO_xxx@SPO__xxx SIP:name1@company.com SMTP:name1@company.com smtp:name1@company.onmicrosoft.com smtp:name2@company.com smtp:name3@company.com X500:/stuff_here with space and /

Open in new window


Note, these can be in any order
smtp:name2@company.com SMTP:name1@company.com smtp:name1@company.onmicrosoft.com SIP:name1@company.com smtp:name3@company.com SPO:SPO_xxx@SPO__xxx 

Open in new window

or might not have all types of addresses
SMTP:name1@company.com smtp:name1@company.onmicrosoft.com SIP:name1@company.com smtp:name3@company.com SPO:SPO_xxx@SPO__xxx 

Open in new window

From the above, I would like to extract the following
name1@company.com, name2@company.com, name3@company.com

Open in new window

1st one is "SMTP:"
the next one are "smtp:" in any order

and thus I would like to drop the following
SPO:SPO_xxx@SPO__xxx (because it starts with "SPO:") 
SIP:name1@company.com (because it starts with  "SIP:")
X500:/stuff_here with space and several /  (because it starts with "X500:") 
smtp:name1@company.onmicrosoft.com  (because it ends with ".onmicrosoft.com")

Open in new window


I have tried to do this in Excel, but it is getting too hard

Clarification: What I am realy trying to do is to re-import all these addresses into the new tenancy, so if there is another way to export/import or sync email addresses, I am opened to alterative solutions
SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use the below script method to exclude the those proxy before you export the data, as that will be easy rather then cleaning it after the export.

$domain="Domain.com" 
$m= get-mailbox -ResultSize unlimited
$d = $m | select Alias, UserPrincipalName, @{"n"="Proxy";E={($_.EmailAddresses | Select-String -Pattern $domain) -join ";" }}
$d = $d | select alias, UserPrincipalName, @{N="Proxy";e={($_.proxy).split(";") | ? {$_ -match "smtp"}}}

Open in new window

Avatar of Alexandre Michel

ASKER

@Sunil, thanks for that. I will try
However, to complicate things, there is more than one domain (domain1.com, domain2.co.uk, etc...)
Should I use your script several times, once for each domain, or is there a better way to do this?
@Vasil, thanks for that. That looks cool. I will try (tomorrow - it is 11:30PM here)

But why does it say "Get-Mailbox vasil"? is that for the "vasil" mailbox only?
What should I use to check all the mailboxes? Maybe I need to use @Sunil's method and yours together???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Vasil, Looking at your 2nd suggestion, how do I get the main email address first and then the aliases after , separated by commas?
@Sunil,

That looks better than I was ever able to do using Excel. Thanks
I am getting these types of answers
smtp:name1@domain.com;smtp:nam1@domain2.com;SMTP:name@domain.com
So it looks like SMTP is that last one

Can I use that string of characters to create the mailboxes in the new Office 365 tenancy?
From what I am reading I need to use for example

Set-Mailbox Angelina -EmailAddress Angelina-NEW01@o365info.com,Angelina-AliasTest02@o365info.com
or
Set-Mailbox Angelina -EmailAddress Angelina-Alias02@o365info.com,Angelina-Alias03@o365info.com,SMTP:Angelina-NEW01@o365info.com
If you keep the prefix, you can directly use the resulting string against the -EmailAddresses parameter as in your last example above, the position of the SMTP entry in the string doesnt matter. So just go with this approach.
you should be good as suggested by Vasil, test with one or two accounts and if any issues let us know...
Thank you both for your input. Saved me hours...