Unable to connect to Exchange Online with PowerShell Runtime 7.2 in Azure Automation

QAadmin 0 Reputation points
2024-09-05T08:58:01.3566667+00:00

Cannot connect to Exchange Online with PowerShell Runtime 7.2 in Azure Automation.
I would like to know how to connect to Exchange Online with Runtime 7.2.

The commands I have tried are as follows.

Connect-ExchangeOnline -ManagedIdentity -Organization customdomain.onmicrosoft.com

get-exomailbox user@custom.domain | Select DisplayName

DisConnect-ExchangeOnline -Confirm:$False

The following error was output.

InvalidOperation: Unable to find type [Microsoft.Exchange.Management.RestApiClient.ExchangeEnvironment].

It succeeds when tried with Runtime 5.1, so it does not seem to be the wrong command.

The settings I have made to prepare my environment are as follows.

  • ExchangeOnlineManagement module installed as Runtime 7.2.
  • As the system-assigned ManagedID is used, check that the status is on in the Automation account under Account Settings > ID > System Assigned.
  • In the Enterprise Applications menu of Entra ID, I looked for this Automation account, a Managed ID account, and added [Exchange.ManageAsApp] from [Office 365 Exchange Online] to the permissions.

The command New-MgServicePrincipalAppRoleAssignment was used.

Confirmed that the permission type has been added as Application.

  • In the ‘Roles and administrators’ menu of the Entra ID, the Automation account was added to the Exchange administrator.

In addition, although we thought it was unnecessary, we also added the following module as Runtime 7.2, but it did not improve the situation.

PackageManagement
PowerShellGet

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,241 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,485 questions
0 comments No comments
{count} votes

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.