List Users Groups And Contact Email Addresses and Alias in Office 365 Using PowerShell
I spend most of my time administering the Exchange side of Office 365 so it pays spend some time experimenting with the commands. The more proficient you are using them the easier your job becomes especially when you need to do something a little more than the web portal is capable of.
List users, groups and contacts E-Mail addresses and Alias
If you don’t know how to get started connecting PowerShell to Office 365 then check out my post here:
If you need to generate a list of all email recipients whether they be users, groups, or contacts you can use the Get-recipient cmdlet. This command by default will only return the name and RecipientType attributes. We can return the list of Email Addresses by piping the objects into the Select statement and choose to return the Displayname, RecipientType and EmailAddresses attributes. Although not shown here the command will also return the types 'MailContact' which are email contacts and 'MailUniversalDistributionGroup' which are email distribution groups.
Get-Recipient | Select DisplayName, RecipientType, EmailAddresses
Sometimes it's easier to export the results to a csv file due to the number of email addresses users and groups can have assigned. Once exported you can manipulate or search the information using Excel.
Get-Recipient | Select DisplayName, RecipientType, EmailAddresses | Export-Csv EmailAddresses.csv
If you are only interested in the primary email address, then use Select to return the DisplayName and PrimarySmtpAddress attributes.
Get-Mailbox |Select-Object DisplayName,PrimarySmtpAddress
If you found this post useful then go buy yourself a copy of my book The Office 365 PowerShell Reference Manual for IT Super Heros!
20th February 2019
Use this if you have over 1000 items.
Get-Recipient -ResultSize Unlimited | Select DisplayName, RecipientType, EmailAddresses | Export-Csv EmailAddresses.csv
18th October 2019
This is great but how would i add a filter to exclude guest users from the report?
(Works but gives every user including guests)
Get-Recipient -resultsize unlimited | Select-Object DisplayName, department, jobtitle | Export-csv c:\users\user\desktop\users.csv
(Gives no results at all)
Get-Recipient -ResultSize unlimited | where($_.usermailbox -eq “usermailbox”) | Export-csv c:\users\user\Desktop\users.csv