Install the module:


Install-Module -Name MSAL.PS

First get the access token:

#Provide your Office 365 Tenant Domain Name or Tenant Id

$TenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

#Used the Microsoft Graph PowerShell app id. You can create and use your own Azure AD App id if needed.

$MsalParams = @{
ClientId = $AppClientId
TenantId = $TenantId 
Scopes = "" 

$MsalResponse = Get-MsalToken @MsalParams
$AccessToken = $MsalResponse.AccessToken

Copy the token and use it for later use, which looks like eyJ0eXAiOxxxxxxxxxxxxxxxx



#Form request headers with the acquired $AccessToken
$headers = @{'Content-Type'="application\json";'Authorization'="Bearer $AccessToken"}

#Provide the required user's ObjectId to check the presence status, which can be find in the Azure AD
$UserId = "2856880d-8a22-4f72-b05e-810879dfd7fc"

#This request gets the online presence status of the given user
$ApiUrl = "$UserId/presence"

#Get the presence status
$Response = Invoke-RestMethod -Method GET -Uri $ApiUrl -ContentType "application\json" -Headers $headers
if($Response -ne $null){
write-host "THe status is: " $Response.availability
Exit 0


This script can also be used to check if Teams service is available