Hi,
Please see this: https://docs.microsoft.com/en-us/azure/automation/enable-managed-identity-for-automation#authenticate-access-with-system-assigned-managed-identity
Tested in my automation account running PowerShell 7.2 in a runtime environment with the Az and Microsoft.Graph.Authentication modules installed.
Code which connects to Azure and Microsoft.Graph using managed identity:
Disable-AzContextAutosave -Scope Process # Ensures you do not inherit an AzContext in your runbook
$azureContext = (Connect-AzAccount -Subscription $SubScriptionId -Tenant $TenantId -Identity).context
Write-Output "-> Setting context"
$azureContext = Set-AzContext -SubscriptionName $azureContext.Subscription -DefaultProfile $azureContext
Write-Output "`n+ Connecting to Graph (Managed Identity)"
Connect-MgGraph -Identity -NoWelcome
Output: