# 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'