Get login name using email address with Powershell

47,510

Solution 1

You can easily accomplish this using:

Get-ADUser -Filter {Emailaddress -eq '[email protected]'}

Solution 2

This command will take input from a TXT file containing user email addresses and output the listed user properties to a CSV file...

Get-Content C:\users.txt | ForEach-Object { ^
  Get-ADUser -Filter {EmailAddress -eq $_} -Properties DistinguishedName,Name,SamAccountName,DisplayName,EmailAddress,LastLogonDate,Enabled ^
  | Select-Object DistinguishedName,Name,SamAccountName,DisplayName,EmailAddress,LastLogonDate,Enabled ^
  | Export-CSV C:\users.csv -Append ^
}
Share:
47,510

Related videos on Youtube

karthick
Author by

karthick

Updated on September 18, 2022

Comments

  • karthick
    karthick almost 2 years

    I need a powershell script, to get login names using the e-mail address. i am having a note with e-mail address of some users. I want to get login IDs and account information of the users in the domain. Can any one help on this.

    Regards, Karthick.

  • karthick
    karthick almost 10 years
    Get-ADUser -Filter {EmailAddress -eq '[email protected]'} -Properties name | Select Name
  • user845218
    user845218 almost 3 years
    Would this work for millions of users? and how much time will it approximately take?