Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get-aduser using emailaddress

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

like image 664
Hans Torres Avatar asked Jun 28 '26 19:06

Hans Torres


2 Answers

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 
}
like image 198
rzantarra Avatar answered Jun 30 '26 09:06

rzantarra


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.

like image 38
Carlos del Rio Avatar answered Jun 30 '26 08:06

Carlos del Rio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!