Unable to connect to Exchange Online with PowerShell Runtime 7.2 in Azure Automation
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