I've been trying to create a new azure function (powershell) which uses managed identity to connect to our exchange online environment.
So as far as I can make out from the documentation I need to use the EXO v3, which I'm doing, and use the following command to setup the connection
Connect-ExchangeOnline -ManagedIdentity -Organization < tenantname >
If I execute my function, it throws an exception
Exception :
Type : System.UnauthorizedAccessException
TargetSite :
Name : CheckResponseHeadersAndGetNewTokenIfNeeded
DeclaringType : Microsoft.Exchange.Management.ExoPowershellSnapin.NewEXOModule
MemberType : Method
Module : Microsoft.Exchange.Management.ExoPowershellGalleryModule.dll
Message : UnAuthorized
Source : Microsoft.Exchange.Management.ExoPowershellGalleryModule
HResult : -2147024891
StackTrace :
at Microsoft.Exchange.Management.ExoPowershellSnapin.NewEXOModule.CheckResponseHeadersAndGetNewTokenIfNeeded(ITokenProvider tokenProvider, HttpResponseHeaders responseHeaders, String errorMessage, String cmdletId, TokenInformation& authHeader, Boolean& isRetryHappening)
at Microsoft.Exchange.Management.ExoPowershellSnapin.NewEXOModule.ProcessRecord()
at System.Management.Automation.Cmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
So I'm guessing the system assigned identity doesn't have the right permissions to access exchange. But I don't seem to be able to figure out how to add these permissions.