Share via


PowerShell: Get-MSOLUSer DisplayName and PrimarySMTPAddress


PowerShell: Get-MSOLUSer DisplayName and PrimarySMTPAddress


Summary

Recent times we came across a situation where a team needs Microsoft Online Users with below information

  • DisplayName
  • PrimarySMTPAddress

The team found this link http://community.office365.com/en-us/f/148/t/75754.aspx and is convinced with the solution posted.

Solution

We can still do this in a more easy way using Regular Expression. Unfortunately, we couldn't reply to the Office365 community and so we decided to share this in TechNet Wiki.

Step 1

Get-MSOLUser -UserPrincipalName 'Chendrayan@domain.onmicrosoft.com' | Select *

Step 2

Get-MSOLUser -UserPrincipalName 'Chendrayan@domain.onmicrosoft.com' | Select -ExpandProperty ProxyAddresses

Step 3

Get-MSOLUser -UserPrincipalName 'Chendrayan@domain.onmicrosoft.com' | 
Select -ExpandProperty ProxyAddresses | 
? {$_ -cmatch '^SMTP\:.*'}

Logic

For All Users with DisplayName

Get-MSOLUser | 
Select DisplayName , @{Name="PrimaryEmailAddress";Expression={$_.ProxyAddresses | 
?{$_ -cmatch '^SMTP\:.*'}}}