Skip to content

Instantly share code, notes, and snippets.

# Your tenant id (Azure Portal 🡪 Azure Active Directory 🡪 Overview)
$TenantID=""
# Microsoft Graph App ID (DON'T CHANGE - Microsoft Graph ID is the same in all tenants)
$GraphAppId = "00000003-0000-0000-c000-000000000000"
#Specify the Managed Identity ID. (Azure Portal 🡪 Azure resource instance (in our example – Automation Account) 🡪 Managed Identity)
$ManagedIdentityID =""
# Add the permission you need for the operation (the below permissions are needed in our scenario)
#Connect-AzAccount using Azure Automation Managed Identity
Connect-AzAccount -identity
#Sign in to MgGraph
function Get-AzToken
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[String]
#Connect-AzAccount using Azure Automation Managed Identity
Connect-AzAccount -identity
#Sign in to MgGraph
function Get-AzToken
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[String]