get-aduser using emailaddress

22,920

Solution 1

What kind of format are you getting this information in?

Personally, I like to make a temporary file then query using a variable in the for loop. For instance, if I had a file that was a list of email addresses at C:\Users\MyUser\Documents\emailList.txt I would do the following:

$my_list = Get-Content C:\Users\MyUser\Documents\emailList.txt
foreach ($x in $my_list){
    $x = $x replace '\s',''
    Get-ADUser -Filter {EmailAddress -eq $x}
}

This will pull a Get-ADuser for the entire list by email address. It will also remove white space, which has caused me issues in this situation in the past. Let me know if you have further questions or if you have trouble getting the above commands to work.

Solution 2

It doesn't look like you are setting up properties for the search result to return. Ie:

Import-csv -Path \\tsclient\c\temp\test.csv -delimiter ";" | ForEach {
Get-ADUser -Filter "EmailAddress -eq '$($_.email)'" -Properties EmailAddress 
}
Share:
22,920
Admin
Author by

Admin

Updated on January 20, 2022

Comments

  • Admin
    Admin over 2 years

    when i want to get some information from an user i use this:

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

    but when i wanna check the information from a bulk of users i try this:

    $batch| foreach {Get-ADUser -Filter {emailaddress -eq $_.email}} 
    

    email is the name of the variable in the CSV file but i am getting this error:

    "Get-ADUser : Property: 'email' not found in object of type: 'System.Management.Automation.PSCustomObject'"

    i can not use the identity because te emailaddess is not supported for this one