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.
Azure AD - How to get the AzureAD user name from Azure Active Directory?
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
4 answers
Sort by: Most helpful
-
-
Andy David - MVP 148.1K Reputation points MVP
2023-02-22T15:39:56.8466667+00:00 Hi there the field is OnPremisesSamAccountName
so if you were to:
get-mguser -UserId first.last@contoso.com -Property OnPremisesSamAccountName | select OnPremisesSamAccountName
you will see it
-
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 :)
-
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