Closed bnc-aymen-guellala closed 5 years ago
@bnc-aymen-guellala In the above, it looks like you used the 'set' command, instead of setting the powershell variable for DebugPreference. i.e., this is how you turn on debug logs:
PS c:\> $DebugPreference="Continue"
In this case, the debug logs will be crucial to discovering the root issue. There are a few known reasons why this might occur
Can you please collect the debug logs for this log-in, setting the debug preference as described?. Feel free to redact tenant and subscription Ids (as long as we can tell the differences between tenants, the actual values are irrelevant).
@bnc-aymen-guellala Ping? This extra information is critical to resolving the issue
$DebugPreference = 'Continue'
#devbnc is OK , cloudbnc is KO
@("devbnc", "cloudbnc") | ForEach-Object {
$tenantName = $_
# Clear Az Context
Write-Host "[$tenantName.onmicrosoft.com] Clear Az context"
while (Get-AzContext) { Disconnect-AzAccount }
Clear-AzContext
Write-Host "[$tenantName.onmicrosoft.com] Connect Azure AD"
$cred = Import-Clixml "$env:OneDrive\PsProfile\Credentials\aymen_guellala_$($tenantName)_onmicrosoft_com.xml"
$cred
Connect-AzureAD -Credential $cred
Write-Host "[$tenantName.onmicrosoft.com] Load current ADUser"
Get-AzureADUser -ObjectId $cred.UserName
Write-Host "[$tenantName.onmicrosoft.com] Connect Az Account"
$cred = Import-Clixml "$env:OneDrive\PsProfile\Credentials\aymen_guellala_$($tenantName)_onmicrosoft_com.xml"
$cred
Connect-AzAccount -Credential $cred
Write-Host "[$tenantName.onmicrosoft.com] Get Az Context"
Get-AzContext | Format-List
Write-Host "[$tenantName.onmicrosoft.com] Get Az Subscriptions"
Get-AzSubscription
Write-Host "[$tenantName.onmicrosoft.com] Clear Az context"
while (Get-AzContext) { Disconnect-AzAccount }
Clear-AzContext
}
@bnc-aymen-guellala Thanks for the extra info. This looks like precisely the second issue, which is that your guest invitation in the second tenant: 72f988bf-86f1-41af-91ab-2d7cd011db47 actually returns a different user display name than you logged in with. Since this account is clearly a guest in this tenant, this is almost certainly because you accepted a guest invitation using a different set of credentials.
You can see a long discussion of this here: https://github.com/Azure/azure-powershell/issues/1665 Closing this in favor of the known issue.
To work around, if you add a -TenantId parameter to your Connect-AzAccount invocation:
Connect-AzAccount -Credential $cred - TenantId 059e96c9-0000-0000-0000-9a23021a8081
this should work around the problem, and since you don't have any subscriptions in the tenant, it shouldn't have any impact.
Description
After connecting AzAccount using a credential object, I am receiving the wrong AccountId in teh Context.
Steps to reproduce
Environment data
Module versions
Debug output