Powershell – How to export / import all email aliases for an Exchange 2010 User Account

emailexchange-2010exportimportpowershell

I have a number of users in our 2010 Exchange server. I wish to export (into a file) all the email addresses for a particular user. Later on, I wish to be able to import all the email addresses once more into the user (lets assume all the emails to be imported do NOT exist in any user account).

Anyone have any ideas how to do this?

Powershell magic, anyone?

Best Answer

I figured out the answer.

In exchange powershell ...

> $mbx = Get-Mailbox someUserName
> $mbx.EmailAddresses | where { $_.IsPrimaryAddress -eq "False" } | Export-CSV "C:\SomePath\wherever.csv"
> $mbx.EmailAddresses | where { $_.IsPrimaryAddress -eq "False" } | foreach { $mbx.EmailAddress -= $_.SmtpAddress }
> Set-Mailbox someUserName -EmailAddresses $mbx.EmailAddresses

> $mbx = Get-Mailbox theNewUser
> Import-CSV "C:\SomePath\wherever.csv" | foreach { $mbx.EmailAddresses += $._SmtpAddress }
> Set-Mailbox theNewUser -EmailAddresses $mbx.EmailAddresses

that's it :)

Of course, you might need to modify the contents of the csv file after the export and before the import.

I also had to delete all the existing email's from the someUserName so there were no duplicates in theNewUser

good luck :)

Related Topic