Find Users by Email or SMTP Proxy Address with Microsoft Graph PowerShell

Learn how to locate users in Microsoft Entra ID by primary email or SMTP proxy address using Microsoft Graph PowerShell.

# Validated on Microsoft.Graph PowerShell SDK v2.29.1
$ErrorActionPreference = 'stop'
$requiredScopes = 'User.Read.All'  

$ctx = Get-MgContext
if (-not $ctx -or ($requiredScopes | Where-Object { $ctx.Scopes -notcontains $_ })) {
    Connect-MgGraph -Scopes $requiredScopes -NoWelcome
}

function Get-UserBySmtpAddress {

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)][string]$Address
    )

    $proxy = if ($Address -notmatch '^smtp:') { "smtp:$Address" } else { $Address }
    $proxy = $proxy.ToLower()

    $proxyEsc = $proxy -replace "'", "''"

    $filter = "proxyAddresses/any(x:x eq '$proxyEsc')"

    Get-MgUser -Filter $filter -Top 1 
}

# ---- Usage ----
# Get-UserBySmtpAddress -Address 'user@domain.com'
Loading...