How to get current Azure Active Directory (AAD) user email from Windows 10

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

To retrieve the email address of the currently logged-in Azure Active Directory (AAD) user from Windows 10, you can use the following PowerShell command:

powershell
(Get-AzureADUser -ObjectId (Get-AzureADUser -ObjectID $([System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value)).UserPrincipalName).Mail

This PowerShell command uses the AzureAD module to query the Azure Active Directory for the user associated with the currently logged-in Windows user. It retrieves the UserPrincipalName (UPN) of the user and then fetches the email address associated with that UPN.

Before running the command, make sure you have the AzureAD PowerShell module installed. You can install it by running the following command in an elevated PowerShell session:

powershell
Install-Module -Name AzureAD

Once the AzureAD module is installed, execute the command to retrieve the email address of the currently logged-in Azure Active Directory user.

Please note that the command assumes the Windows user is signed in using an Azure AD account, and the associated Azure AD user has an email address assigned. If the command doesn't return the expected email address, verify that the Windows user is signed in with the correct Azure AD account and that the account has an email address associated with it in Azure AD.