microsoft / MSCloudLoginAssistant

PowerShell Module Handling Authentication to Cloud Services
https://www.powershellgallery.com/packages/MSCloudLoginAssistant/
MIT License
76 stars 52 forks source link

Connect-M365Tenant cannot connect to ExchangeOnline with Managed Identity #186

Open raandree opened 15 hours ago

raandree commented 15 hours ago

When trying to connect to ExchangeOnline using Connect-M365Tenant

Connect-M365Tenant -Workload ExchangeOnline -Identity -TenantId MngEnvMCAP576786.onmicrosoft.com

you may get the following error:

Value cannot be null.
Parameter name: Organization cannot be null for Managed Identity based connections.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.4.0\netFramework\ExchangeOnlineManagement.psm1:762 char:21
+                     throw $_.Exception.InnerException;
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], ArgumentNullException
    + FullyQualifiedErrorId : Value cannot be null.
Parameter name: Organization cannot be null for Managed Identity based connections.

Unfortunately, the error handling obfuscates the real error.

In case of the error, Get-MSCloudLoginOrganizationName does not return anything.

Get-MSCloudLoginOrganizationName -Identity
raandree commented 15 hours ago

Reason for this bug is that Get-MSCloudLoginOrganizationName uses Get-MgDomain internally. Get-MgDomain is defined in Microsoft.Graph.Identity.DirectoryManagement but this module is not a dependency of Microsoft365DSC.