After connecting to your Azure AD using the Connect-AzureAD cmdlet, you will try to retrieve information about your Azure Active Directory, but you may get the following error:
Get-AzureADDomain : Error occurred while executing GetDomains
Code: Authentication_Unauthorized
Message: User was not found.
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
Error
Fix
This error means that you are connecting to Azure AD without privileges or you are conencting to the wrong Tenant ID.
PS C:\WINDOWS\system32> Connect-AzureAD Account Environment TenantId TenantDomain AccountType ------- ----------- -------- ------------ ----------- xxxxxxxxxxxxxxxxxxxxx AzureCloud YYYYYYYYYYYYYYYYYYYYYYY User
In this case, TenantDomain is “User” which is wrong. To ensure connection to the expected Azure AD Domain, the tenant ID must specified:
PS C:\WINDOWS\system32> Connect-AzureAD -TenantId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Account Environment TenantId TenantDomain AccountType ------- ----------- -------- ------------ ----------- yyyyyyyyy@yyyyy.yyy AzureCloud xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx yourdomain.onmicrosoft.com User
Note: The tenant ID can be retrieved using the Get-AzureRmContext cmdlet.
Now you can run the Get-AzureADDomain cmdlet and you will get all the information about your Azure AD.
Thanks for reading! You can follow me on Twitter @PrigentNico