Trouble using Microsoft.Graph with Azure Automation Runbooks

Charles ORourke 0 Reputation points
2023-02-07T18:13:24.3833333+00:00

0

I'm working on integrating Microsoft.Graph functionality in Azure Automation Runbooks with Powershell, but I keep encountering an error when trying to connect to Microsoft.Graph in the runbook itself. Here's the code in the runbook:

Connect-MgGraph -ClientID "<clientid>" -TenantID "<tenantid>" -CertificateThumbprint "<thumbprint>"

This code works in Azure CLI and through PowerShell ISE connected to our Azure instance, but when it's run in the Automation Runbook it can't connect to Microsoft.Graph and shows an error that says:

"A socket operation encountered a dead network."

The network is up and running, we are able to connect to ExchangeOnline with no issue. Has anyone seen this before or can point me in the right direction?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,308 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,331 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,877 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 44,666 Reputation points
    2023-02-09T08:10:49.9166667+00:00

    Hello there,

    According to your description ,as far as I know ,a socket operation encountered a dead network. This could indicate a serious failure of the network system (i.e. the protocol stack that the WinSock DLL runs over), the network interface, or the local network itself. This error can happen when the network cable gets disconnected or the network becomes otherwise inaccessible.

    Use PowerShell 7+

    Only load the Microsoft.Graph modules you template needs

    Set $maximumfunctioncount to its max value of 32768.

    This article describes runbook issues that might occur and how to resolve them. https://learn.microsoft.com/en-us/azure/automation/troubleshoot/runbooks

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  2. Limitless Technology 44,666 Reputation points
    2023-02-09T08:11:02.37+00:00

    Hello there,

    According to your description ,as far as I know ,a socket operation encountered a dead network. This could indicate a serious failure of the network system (i.e. the protocol stack that the WinSock DLL runs over), the network interface, or the local network itself. This error can happen when the network cable gets disconnected or the network becomes otherwise inaccessible.

    Use PowerShell 7+

    Only load the Microsoft.Graph modules you template needs

    Set $maximumfunctioncount to its max value of 32768.

    This article describes runbook issues that might occur and how to resolve them. https://learn.microsoft.com/en-us/azure/automation/troubleshoot/runbooks

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  3. SwathiDhanwada-MSFT 18,901 Reputation points
    2023-02-12T19:00:02.1533333+00:00

    Charles - When you receive errors during runbook execution in Azure Automation, you can use the following steps to help diagnose the issues:

    1. Ensure that your runbook script executes successfully on your local machine. For language reference and learning modules, see the PowerShell Docs or Python Docs. Running your script locally can discover and resolve common errors, such as:
      • Missing modules
      • Syntax errors
      • Logic errors
    2. Investigate runbook error streams. Look at these streams for specific messages, and compare them to the errors documented in this article.
    3. Ensure that your nodes and Automation workspace have the required modules. If your runbook imports any modules, verify that they're available to your Automation account by using the steps in Import modules. Update your PowerShell modules to the latest version by following the instructions in Update Azure PowerShell modules in Azure Automation. For more troubleshooting information, see Troubleshoot modules.
    4. If your runbook is suspended or unexpectedly fails:
    5. Do this step if the runbook job or the environment on Hybrid Runbook Worker doesn't respond. If you're running your runbooks on a Hybrid Runbook Worker instead of in Azure Automation, you might need to troubleshoot the hybrid worker itself.

    Reference Document : https://learn.microsoft.com/en-us/azure/automation/troubleshoot/runbooks

    0 comments No comments

Your answer

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