FunctionsPublic/Get-GraphUser.ps1

<#
.SYNOPSIS
Get Microsoft Graph Access Token
 
.DESCRIPTION
Function uses a Client ID and Client Secret with a username and password to authenticate against a specific AAD tenant and obtains an access token.
#>

function Get-GraphUser
{
    param([psobject]$accessToken, [string]$username)
    #
    # Get user
    #
    $responseBody = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/$($username)" -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"}
    $jsonResponse = $responseBody | ConvertTo-JSON

    $retrievedUser = ConvertFrom-Json -InputObject $jsonResponse

    return $retrievedUser
}