Search code examples
azurepowershellazure-active-directoryazure-cli

Find a user in Azure Active Directory based on any of their email addresses


I needed to find a user based on their email address (to which they had received a license) and then connect that back to their primary identity for our internal billig.

In AD there are 2 fields that hold the emails:

  • email
  • proxyAddresses.*

How can I find the actual user's identity based on any 1 of their email addresses


Solution

  • Finding a user by their primary email address is quite simple:

    # user based on primary email
    & az ad user list --query "[?mail=='$email'].userPrincipalName"
    

    Finding a user based on an email alias is a bit harder. In our case these are all stored in the proxyAddresses field in their user profile and the values are prefixed with smtp:. To find them use:

    # user based on alias
    & az ad user list --filter "proxyAddresses/any(p:p eq 'SMTP:$email')" --query "[].userPrincipalName"