AD email

This topic contains 11 replies, has 5 voices, and was last updated by Profile photo of Brad Brad 2 months, 1 week ago.

  • Author
    Posts
  • #54429
    Profile photo of Brad
    Brad
    Participant

    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.

  • #54430
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

  • #54432
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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

  • #54444
    Profile photo of Brad
    Brad
    Participant

    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

  • #54447
    Profile photo of ertuu85
    ertuu85
    Participant

    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 2 months, 1 week ago by Profile photo of ertuu85 ertuu85.
  • #54453
    Profile photo of Brad
    Brad
    Participant

    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

  • #54457
    Profile photo of ertuu85
    ertuu85
    Participant

    Computers dont have email addresses assigned to them in AD

  • #54458
    Profile photo of Brad
    Brad
    Participant

    🙂 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

  • #54459
    Profile photo of Brad
    Brad
    Participant

    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

  • #54462
    Profile photo of Brad
    Brad
    Participant

    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

  • #54469
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
    }
    
  • #54513
    Profile photo of Brad
    Brad
    Participant

    THANK YOU Rob,

    this is exactly what i was looking for

    Thanks for your help.

You must be logged in to reply to this topic.