An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Tristan Marzec. You are running a PowerShell 7.2 runbook in Azure Automation with the Microsoft.Graph.Authentication 2.35.1 and Microsoft.Graph.Groups 2.35.1 modules. When calling Connect-MgGraph, you get an error about missing assembly System.Diagnostics.DiagnosticSource v8.0.0.0. This indicates a runtime incompatibility rather than a simple module import issue.
This is the Assembly load error when using Connect-MgGraph in PowerShell 7.2 runbooks. This is because Microsoft.Graph v2.35.1 depends on .NET 8 assemblies, but the 7.2 runbook runtime is based on .NET 6.
The other alternative solution is Upgrade to PowerShell 7.4 runtime in Azure Automation (built on .NET 8) for the long-term support, or downgrade Microsoft.Graph to a version with .NET 6.
Here are the steps to fix:
Upgrade to PowerShell 7.4:
- Go to the Azure portal and select your Automation account.
- Under Process Automation, select Runtime Environments. If you don't find Runtime Environments in the list,
- Select Try Runtime environment experience in the Overview page to switch to the new portal interface.
- Select Create to create a new PowerShell 7.4 Runtime.
- On the Basics tab, provide the following details:
- Enter Name for the Runtime environment. It must begin with alphabet and can contain only alphabets, numbers, underscores, and dashes. From the Language dropdown list, select PowerShell.
- In Runtime version for scripting language, select 7.4 and Enter appropriate Description.
- On the Packages tab, in the Package version dropdown list, you would see default Az and Azure CLI packages already present.
- Select +Add from gallery to add your packages
Microsoft.Graph.Authentication 2.35.1 andMicrosoft.graph.Groups 2.35.1from gallery and select Next.
- On the Review + create tab, review the entries and select Create.
Update PowerShell Runbook in Azure Runtime Environment - Azure Automation | Microsoft Learn
Now create a Runbook using the PowerShell version 7.4 and add your script then run your Runbook
Downgrade Graph SDK
- Remove the current Graph modules from your Automation account.
- Install older versions compatible with .NET 6:
Install-Module Microsoft.Graph.Authentication -RequiredVersion 2.25.0
Install-Module Microsoft.Graph.Groups -RequiredVersion 2.25.0
- Update your runbook to use these versions.
Test again Connect-MgGraph should work in 7.2.
Hope this helps. and please feel free to reach out if you have any further questions. Thanks