Forum Discussion
Script to add first.last@domain.com to exisiting Office 365 setup
Hello,
After searching on the web I am looking for a script or help with a script that will add an alias of first.last@domain.com to all users on Office 365. This is an all online setup. I understand I will probably have to do this via csv file and import it that way to the existing users but any assistance would be appreciated.
Noel
2 Replies
- Liam KempCopper Contributor
Hi Noel,
I find a CSV file to be the easiest way to make sure I have the addresses correct, rather than finding out later i had an error in my script trying to do the names programmatically.
If you are just adding a new proxy email address (rather than changing the primary, if you want to change the primary, read further down) all the csv file needs is username and emailaddress
username,emailaddress
john.smith,john.smith@domain.com
sally.smith,sally.smith@domain.com
The basic process here is
Connect to exchange online via PowerShell
# connect to office 365 exchange online $creds = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $creds -Authentication Basic -AllowRedirection # import session Import-PSSession $session
Then we can import the csv and use the Set-Mailbox cmdlet using the add syntax like this
#import csv file $csv = import-csv 'C:\temp\users.csv' # Add additional email address to each user $csv | foreach {set-mailbox -identity $_.username -emailaddresses @{add="$_.emailaddress"}If you are changing the primary SMTP address
I would take a look at this script by Paul Cunningham
https://gallery.technet.microsoft.com/office/Bulk-Add-SMTP-Addresses-to-e3d28842
Good luck!
Liam
- Noel SearlesCopper Contributor
Thank you. I will give this a shot. It looks very logical and that it would work fine though. Also, I came across Paul's work as well so that will be handy at a future time I'm sure!
Thanks again for your help! I will mark the answer complete hopefully today (11/21/17)