How to connect to ExchangeOnline to Get-DistributionGroup

Elvis Eyobor 0 Reputation points
2024-10-29T19:21:21.8833333+00:00

Hi Guys,

I am trying to create and also get distribution list using a powershell runbook (version 5.1) setup in an Azure Automation account. But am having trouble connecting to Exchange Online.

=========

My Script (1):-

Connect-ExchangeOnline -ManagedIdentity -Organization "contoso.onmicrosoft.com"

Get-DistributionGroup

ERROR MESSAGE:

This throws the Unauthorized error

========

I have registered an app in Azure and assigned necessary permissions.

(- Exchange.ManageAsApp, - Group.Read.WriteAll)

Please any help would be much appreciated. Thanks

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
709 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,609 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andy David - MVP 149.7K Reputation points MVP
    2024-10-29T19:28:07.83+00:00

    Did you follow these steps? Including adding the Exch Role to the service principal?

    https://practical365.com/use-azure-automation-exchange-online/


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.