Author Posts

September 22, 2016 at 2:22 pm

Hi,
try to find user email
i have user computer name, from ad i can get user computer name:
$compname = "Test1"
$compuser = Get-ADComputer -Filter ("Name -Like '*$compname*'") -Property * |
Select Description
$compuser

now i have First and Last Name,
How i can find email address in AD?

Thanks.

September 22, 2016 at 2:23 pm

Remove " | Select Description" – it's limiting your output.

September 22, 2016 at 2:27 pm

Leverage the Get-ADUser cmdlet to get an AD user object and access the "mail" property.

$user = Get-ADUser ...
$user.mail

Check out the examples at the end of the following page:
https://technet.microsoft.com/library/ee617241.aspx

September 22, 2016 at 4:14 pm

Thank you both,

i try, and now i know why its not working and i need help

when i get Description from computer record, i have FirstName and LastName,
but in user account Display name set LastName, FirstName
i try : Get-ADUser -Filter {Name -like "%$compname%"} -Properties Mail | Format-List

and nothing.

Thanks

September 22, 2016 at 4:24 pm

You should be able to get the same results with something like this:

get-aduser -identity USER1 -properties givenname, surname, mail | select givenname, surname, mail

Are you trying to get username or a computer name with this? %compname%...get-aduser will only retrieve users in AD
Get-ADUser -Filter {Name -like "%$compname%"} -Properties Mail | Format-List

get-aduser -identity User1-properties givenname, surname, mail | select @{e = {$_.surname};n="Lastname"}, @{e={$_.givenname};n="Firstname"}, @{e={$_.mail};n="Email"}

Lastname Firstname Email
-------- --------- -----
1        User      user1@mail.com
  • This reply was modified 1 year, 11 months ago by  ertuu85.

September 22, 2016 at 4:36 pm

Hi Ertuu85,

thx, for your exp,
this in what i try to do
i have computername – Test1
i can get computer description( and this is user name),then i try find email for this user

Thx

September 22, 2016 at 5:13 pm

Computers dont have email addresses assigned to them in AD

September 22, 2016 at 5:59 pm

🙂 i know

i have computername = Test1
i can get computer description( this is user name), and then with this Description(User Name)

i need find email for this user

Thanks

September 22, 2016 at 6:31 pm

how i can can change this:

i have First and Last Name(Tom Jhons), how i can change it on Tom.Jhons@test.com

Thanks

September 22, 2016 at 7:04 pm

or how i can split Tom Jhons
exp:
$compname = "Test1"
$compuser = Get-ADComputer -Filter ("Name -Like '*$compname*'") -Property * |
Select Description
$compuser

and result: Tom Jhons

how i can split this to:

$givenname = Tom
$surname = Jhons

Thanks

September 22, 2016 at 7:55 pm

This is a basic, untested example. You need to get the description, split at the spaces and then get the parts of the name:

$Description = Get-ADComputer -Filter "Name -eq 'Computer123'" -Properties Description | Select -ExpandProperty Description

if ($Description) {
    $arrDesc = $Description -split " "
    $givenname = $arrDesc[0]
    $surname = $arrDesc[1]
    #Keep in mind a search can have more than one result.  This example assumes there is on result
    $email = Get-ADUser -Filter "givenName -eq '$givenname' -and surName -eq '$surname'" -Properties mail | Select -ExpandProperty mail
}

September 23, 2016 at 11:57 am

THANK YOU Rob,

this is exactly what i was looking for

Thanks for your help.