Connect to AzureAD

Moonlight 176 Reputation points
2020-12-13T12:59:11.657+00:00

Hello

I tried to connect to AzureAD from my powershell with global admin user but when i tried to apply any Azure powershell command i have the below error

PS C:\Windows\system32> Get-AzureADUser -Top 10
Get-AzureADUser : Error occurred while executing GetUsers
Code: Authentication_Unauthorized
Message: User was not found.
RequestId: afeb378f-4388-4ae2-88bf-653410122329
DateTimeStamp: Sun, 13 Dec 2020 12:51:32 GMT
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
At line:1 char:1

  • Get-AzureADUser -Top 10
  • ~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Get-AzureADUser], ApiException
  • FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetUser
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,633 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Cristian SPIRIDON 4,471 Reputation points
    2020-12-13T16:28:43.79+00:00

    You need first to authenticate to Azure.
    I would recommend to use latest powershell module for Azure Az.
    To connect to azure you need to use:

    Connect-AzAccount  
    

    To get users you have:

    Get-AzADUser  
    
    1 person found this answer helpful.
    0 comments No comments

  2. JamesTran-MSFT 36,541 Reputation points Microsoft Employee
    2020-12-14T20:00:42.413+00:00

    @Moonlight
    Thank you for the detailed post! If you have the most recent AzureAD PS modules, you can try the below to hopefully resolve your issue.

    TS Steps:
    The accounts I used - Outlook user and Tenant specific user, both Global Admins.
    47990-image.png

    I replicated the error that you are receiving by signing into my Outlook account.
    47948-image.png

    I created a new test user, within my tenant and re-tried the operation, which was successful.
    48094-image.png

    I hope this helps! If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    1 person found this answer helpful.

  3. hitokiri8384 1 Reputation point
    2021-05-24T21:07:53.227+00:00

    Hi. Im getting the same error. I recently created this azure free account. Im only getting this error when I user powershell ISE or visual stuido code apps on my computer. When I try the same using the cloudshell on azure it is working. can you help me please? carlo_vergara@harsh.com .com

    0 comments No comments

  4. amit tiwari 1 Reputation point
    2021-10-19T19:00:36.207+00:00

    I was also facing the same issue a few days back
    steps to resolve it
    step1-cross-check tenant id from your ADD account and Tenant ID which you get after connection,If both are different then you have to modify your connect-AzureAD command

    step2-you need to use the below command to rectify it and everything will work like a charm.

    connect-AzureAD -TenantID <you tenant id from ADD acount>

    0 comments No comments