FunctionsPublic/Find-GraphUserByEmailAddress.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function Find-GraphUserByEmailAddress
{
    param(
        [psobject]$accessToken, 
        [string]$emailAddress
    )

    #
    # Get user by email address
    #
    $responseBody = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/$($emailAddress)" -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    $jsonResponse = $responseBody | ConvertTo-JSON
    $users = ConvertFrom-Json -InputObject $jsonResponse
    
    return $users
}