Powershell logged in user email

OzDownUnder 156 Reputation points
2023-01-31T23:28:36.4+00:00

I'm using Connect-AzureAD to login to Azure AD. I would like to get the email address of the user that's logged in so that I can use that for logging it into a log file but can't seem to find a way to get the logged in users email using powershell. Any suggestions appreciated.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,631 questions
0 comments No comments
{count} votes

Accepted answer
  1. Givary-MSFT 30,931 Reputation points Microsoft Employee
    2023-02-03T08:59:12.12+00:00

    @OzDownUnder Thank you for reaching out to us, As I understand you want to know the email address of the user while connecting to PowerShell via Connect-AzureAD.

    Researched on this and found this cmdlet which can provide the email address of the current session (connect-azuread) who logged in

    Get-AzureADUser -ObjectId (Get-AzureADCurrentSessionInfo).Account.Id | select mail

    User's image

    Let me know if you have any further questions, feel free to post back.

    (Get-AzureADUser -ObjectId (Get-AzureADCurrentSessionInfo).Account.Id)
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful