MS Graph API Part 1: Connect to MS Graph API


In this vlog series I will show you how you can use the Microsoft Graph API  ("Graph API") to manage Azure Active Directory. 

In the first episode I will demonstrate how-to setup a connection to the Graph API, and retrieve all the users account from the Azure AD tenant.

The  AzureAD_GraphTokenviaSecret  script  used in the video. Please modify the red parameters to your own values.

# Example file from
# Setup Microsoft 365 environment
# Microsoft graph api documentation:

# Minimum Required API permission for execution to list users
# User.Read.All

# Connection information for Graph API connection - specific to Agency
$clientID = "xxxxxxx-xxxx-xxxx-xxxxxxxxx" #  App Id MS Graph API Connector App registration
$tenantName = "<<mytenantname>>" # your tenantname (example:
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Secret MS Graph API Connector App registration
$resource = ""
$ReqTokenBody = @{
    Grant_Type    = "client_credentials"
    Scope         = ""
    client_Id     = $clientID
    Client_Secret = $clientSecret
$TokenResponse = Invoke-RestMethod -Uri "$tenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$TokenAccess = $Tokenresponse.access_token

# Get all Azure AD Users via Microsoft Graph API
$GetUsersUrl = ""
$Data = Invoke-RestMethod -Uri $GetUsersUrl -Headers @{Authorization = "Bearer $($TokenAccess)" }  -Method Get 
$Result = ($Data | select-object Value).Value
$Users = $Result | select DisplayName,UserPrincipalName,Id

Have your own Azure AD test environment for free:

Download Visual Studio Code:

Download the script via Github: