Azure AD - How to get the AzureAD user name from Azure Active Directory?

SujanChristo 6 Reputation points
2023-02-22T12:19:02.01+00:00

Hi Team,

We are on Microsoft 365 and using AzureAD for authentication in our Windows 10 / 11 machines. We are in need of getting the AzureAD/Username either from Azure Active Directory using Powershell or C# for all the members in the AzureAD environment.

We are searching for this for quite sometime but in vain.

Any help on this would be of greatly appreciated!

Thanks in advance,

With Warm Regards,

Sujan

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Developer technologies | C#
{count} vote

4 answers

Sort by: Most helpful
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2023-02-23T12:35:54.8566667+00:00

    ah, ok, if not syncing then you wont be able to get that value from on-prem, short of maybe populating it yourself manually with a script or something and using a custom attribute in Azure perhaps.

    https://learn.microsoft.com/en-us/azure/active-directory/external-identities/user-flow-add-custom-attributes

    1 person found this answer helpful.

  2. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2023-02-22T15:39:56.8466667+00:00

    Hi there the field is OnPremisesSamAccountName

    so if you were to:

    get-mguser -UserId ******@contoso.com -Property OnPremisesSamAccountName | select OnPremisesSamAccountName
    

    you will see it


  3. Sujan Christo 1 Reputation point
    2023-03-01T08:00:24.62+00:00

    @Andy David - MVP . thanks a lot for your time and clarifications. That make things clear for us :)

    0 comments No comments

  4. Sujan Christo 1 Reputation point
    2023-03-01T08:05:30.9333333+00:00

    Hi @Andy David - MVP , Did a quick try with both PowerShell and GraphExplorer (https://graph.microsoft.com/v1.0/users/{userObjectId}?$select=onPremisesSamAccountName) and the value returned is null.

    Please note that we are NOT using On-premises Active Directory and Azure AD Connect for Syncing. The machines are directly authenticated with Azure Active Directory.

    Sorry, missed to let you know this scenario earlier :)

    Under this current setup, will we be able to get the onPremisesSamAccountName from AzureAD?

    Kindly share your thoughts on this.

    Thanks a bunch for your time.

    WIth Warm Regards,

    Sujan


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.