ExchangeOnlineManagement authentication broken in Azure Automation Runbook

Steve Johnson 11 Reputation points
2023-02-11T12:03:47.8666667+00:00

Since the morning of Thursday 9 Feb 2023, I've not been able to successfully authenticate with ExchangeOnlineManagement via an Azure Automation runbook using either a credential flow or Managed Identity. I can replicate this issue across three different tenants on three different subscriptions. It was working fine up until Thursday, now I get the following error:

PowerShell v5.1 / ExchangeOnlineManagement v3.1.0 using Managed Identitypwsh_exo_v5_error

PowerShell v7.1 / ExchangeOnlineManagement v3.1.0 using Managed Identitypwsh_exo_v7_error

PowerShell v7.1 / ExchangeOnlineManagement v3.1.0 using Credential flow

pwsh_exo_v7_error_cf

Microsoft Exchange Online
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,261 questions
{count} vote

6 answers

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,386 Reputation points
    2023-03-01T03:59:19.8833333+00:00

    @Steve Johnson , Rajesh1257, Martyn Burgess - based on the investigation it appears that some of the default PS modules are not getting loaded in the script when it is executing in the Azure Sandbox. In addition to EXO module please upload the following modules as well to Automation Account to ensure that they are available for loading by the runbook job -  

    1. PowerShell Gallery | PackageManagement 1.4.8.1 and 
    2. PowerShell Gallery | PowerShellGet 2.2.5 

    Hope this helps. Please let us know if you have any questions.

    5 people found this answer helpful.

  2. Alexandros Kanakaris 36 Reputation points
    2023-08-02T11:39:25.31+00:00

    Azure Automate, is a flying circus. I have been so disappointed by this service and module; I feel it is a pack of crumbling pieces.

    Issue after an issue after an issue. Latest one is the same code snippet failing on one runbook and working on the other, both on the same Runtime and Automation account.

    Really, Azure automate should NOT be considered a dependable service, rather something in Preview.


  3. Alexandros Kanakaris 36 Reputation points
    2023-08-02T11:49:21.2266667+00:00

    Just to give an idea of the mess, if one tries to do this, it works.

    Get-EXORecipient -ResultSize Unlimited
    

    BUT if the poor fellow, also tries to import another needed Module (from the Azure ones!) this is what they get for the same snippet.

    Import-Module Az.Storage
    
    Get-EXORecipient: 
    Line |
      28 |  $ValidAddresses = Get-EXORecipient -ResultSize Unlimited
         |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Could not load file or assembly 'Microsoft.OData.Core, Version=7.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)
    
    0 comments No comments

  4. Alexandros Kanakaris 36 Reputation points
    2023-08-02T11:55:05.8433333+00:00

    You want more? Disconnect-ExchangeOnline, the most basic cmdlet, fails to execute on Runtime 7.2 with an erroneous Job fail and without any exception logged.

    Does not work as any of the below:

    Disconnect-ExchangeOnline -Confirm:$False

    (access denied error)

    Disconnect-ExchangeOnline -ConnectionId


  5. Alexandros Kanakaris 36 Reputation points
    2023-08-02T12:36:18.38+00:00

    So, yet another bug and how to solve it.

    If you want to use Az.Storage on the same Runbook with EXOv3, you will need to not use:

    Get-EXORecipient -ResultSize Unlimited
    

    You will use, as this one works.

    Get-Recipient -ResultSize Unlimited
    
    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.