Granting a Managed Identity (Automation Account or Logic App) access to a Microsoft Graph using the Microsoft Graph SDK for PowerShell and the Get-MgServicePrincipal and New-MgServicePrincipalAppRoleAssignment cmdlets.

PowerShell Code

Note: This code requires the Microsoft Graph SDK for PowerShell.