top of page
Writer's pictureAbhijit Tiwari

How to get list of email addresses associated to a mailbox from Office 365/ Exchange Online?


I was going though a case where a customer wanted to get rid of a domain and for some reasons,each time he tried to remove the domain he would get to see this, after waiting almost for hours:-

Problem is that sometimes office 365 portal won't give you a correct error message while removing a domain and there is a good chance that an object is blocking domain removal because its associated with the domain which you are trying to remove. I had tried using powershell to get this issue fixed and I found that there were objects that were using the custom domain , and most of them were user account. So the user wanted to get a list of the mailboxes that were using the custom domain and I created a couple of them to get the results.

Before we proceed any further. Let me remind you that we would be connecting to a powershell session to Exchange Online. If you are not aware of the process, please refer to the following link :-

Note:Before you copy and paste the below scripts , make sure you format them in a single line.

Commands to get Primary SMTP Addresses (Download):-

Make sure you copy and run the script in a single line as shown below, since my blog doesn't allow me to paste code, the clipboard might also copy white spaces which might case errors.Once you run the script You shall get the following output, where the email address would contain the prefix SMTP meaning that these all are primary SMTP or Email addresses

Commands to get Secondary SMTP Addresses (Download):-

Make sure you copy and run the script in a single line as shown below, since my blog doesn't allow me to paste code, the clipboard might also copy white spaces which might case errors.Once you run the script You shall get the following output, where the email address would contain the prefix smtp (Note that this is in small case) meaning that these all are primary SMTP or Email addresses

Commands to get email address from custom domain Addresses (Download):-

Note:Here I have used my domain mspathshala.com, you need to enter the domain name you are looking for.

Make sure you copy and run the script in a single line as shown below, since my blog doesn't allow me to paste code, the clipboard might also copy white spaces which might case errors.Once you run the script You shall get the following output:-

Commands to get email address containing onmicrosoft.com:-

Note: Few tenants also contain the domain name microsoftonline.com, you can modify the "onmicrosoft.com" value to get results for microsoftonline.com domain

Make sure you copy and run the script in a single line as shown below, since my blog doesn't allow me to paste code, the clipboard might also copy white spaces which might case errors.Once you run the scriptYou shall get the following output:-

Hope this was informative, Enjoy!!!

668 views0 comments

תגובות


bottom of page