get-aduser using emailaddress

Hans Torres picture Hans Torres · Dec 19, 2017 · Viewed 16.6k times · Source

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

Answer

rzantarra picture rzantarra · Dec 19, 2017

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 
}