Share via

Unable to use imported MSGraph Commands in Automation Runbook

Tristan Marzec 20 Reputation points
2026-03-12T10:58:23.6233333+00:00

I have developed a powershell runbook and I want to use the commands from these modules:

Microsoft.Graph.Authentication 2.35.1

Microsoft.graph.Groups 2.35.1

I am using the 7.2 runtime version. My issue is that I am unable to use this command:

Connect-MgGraph

When I run the script in the runbook environment I just receive this error:
Connect-MgGraph: Line | 27 | Connect-MgGraph -Identity -ClientId $ClientId | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Is this a version mismatch or just a problem of the runbook environment itself?

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

{count} votes

Answer accepted by question author
  1. Bharath Y P 6,560 Reputation points Microsoft External Staff Moderator
    2026-03-12T12:51:06.6266667+00:00

    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:

    1. Go to the Azure portal and select your Automation account.
    2. Under Process Automation, select Runtime Environments. If you don't find Runtime Environments in the list,

    User's image

    1. Select Try Runtime environment experience in the Overview page to switch to the new portal interface.
    2. Select Create to create a new PowerShell 7.4 Runtime.
    3. On the Basics tab, provide the following details:
    4. 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.
    5. In Runtime version for scripting language, select 7.4 and Enter appropriate Description.
    6. On the Packages tab, in the Package version dropdown list, you would see default Az and Azure CLI packages already present.
    7. Select +Add from gallery to add your packages Microsoft.Graph.Authentication 2.35.1 and Microsoft.graph.Groups 2.35.1 from gallery and select Next.

    User's image

    1. 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

    1. Remove the current Graph modules from your Automation account.
    2. 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
    
    1. 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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.