Reputation: 1
I am using a system managed identity in an Azure Automation account. Separately, I gave the identity (Application) all the Graph access it requires. I am leveraging the Az module to get the access token, which I then pass to connect-mggraph. Natively, the MgGraph module does not yet support the managed identity natively.
Here is the code I am using to attempt the connection. My expectation is that the "connect-mgraph" will succeed using the managed identity.
Connect-AzAccount -Identity
$token = Get-AzAccessToken -ResourceTypeName MSGraph
Connect-MgGraph -AccessToken $token.token
This is the returned error:
3 | Connect-MgGraph -AccessToken $token.token
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0,
| Culture=neutral, PublicKeyToken=30ad4fe6xxxxxxxx'. The system cannot
| find the file specified.
Get-MgGroup_List: C:\Temp\jka4ters.qmd\f1cc4605-9c45-4b6e-a89a-xxxxxxxxxxxx.ps1:5
I've tried various minor alterations to the code, but always get the same error. Others seem to have success with this online. Any ideas?
Upvotes: 0
Views: 1857
Reputation: 10292
I tried in my environment and got below results:
Initially I tried the same commands in automation(powershel-7.1) and got same error.
Console:
Instead of using -ResourceTypeName MSGraph
I have used -ResourceUrl "https://graph.microsoft.com"
in below commands.
Also please ensure that you have using both module and runbook
in same runtimeversion.
#Connect to Microsoft Graph within Azure Automation
Connect-AzAccount -Identity
$token = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com"
Connect-MgGraph -AccessToken $token.Token
After I executed above commands the MgGraph
is connected successfully.
Console:
Upvotes: 0