which active directory cmdlet has primarysmtpaddress as a property

This topic contains 4 replies, has 3 voices, and was last updated by  Art Beane 4 years, 3 months ago.

  • Author
    Posts
  • #9417

    Robert Duncan
    Participant

    Hi,

    I am looking for the property primarysmtpaddress, get-aduser has a property called mail but this returns the proxyaddress – how do I get the primarysmtpaddress without using the exchange or quest cmdlets?

    thanks,
    Rob.

  • #9421

    Dave Wyatt
    Moderator

    The ActiveDirectory cmdlets don't know anything about Exchange extensions, so you'd have to access the LDAP properties directly. I haven't worked with Exchange much, but based on this link, it looks like the "primary SMTP Address" is part of the proxyAddresses multi-valued attribute. Specifically, it's the element that begins with "SMTP:" in upper-case.

    So you'd have to do something like this:

    $user = Get-ADUser -Identity SomeUser -Properties proxyAddresses
    $primarySMTPAddress = ""
    foreach ($address in $user.proxyAddresses)
    {
        if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:'))
        {
            $primarySMTPAddress = $address.SubString(5)
            break
        }
    }
    
    Write-Host "PrimarySMTPAddress: $primarySMTPAddress"
    
  • #9422

    Art Beane
    Member

    In the ProxyAddresses property, the primary smtp address will be the one matching 'SMTP' (all upper case characters). One way to get it is to do this:

    Get-ADUser -Identity  -Properties ProxyAddresses | Where-Object {$_.ProxyAddresses -cmatch "SMTP"}
  • #9429

    Robert Duncan
    Participant

    Thanks for the quick response guys, I can select the property ProxyAddress but how to only output the primary SMTP address,
    perhaps I am focusing on the wrong cmdlet, I can get the value pretty easily using the quest cmdlets

    Get-QADUser -Identity -IncludedProperties primarysmtpaddress | select primarysmtpaddress

    I am new to powershell but thought this would be a pretty straight forward filter on ad user object?

    thanks,
    Rob.

  • #9435

    Art Beane
    Member

    Get-ADUser doesn't return a PrimarySMTPAddress object. The only way to get it is to retrieve the entry in the ProxyAddress array with the case sensitive 'SMTP' string. Dave's suggestion looks like a good way to proceed.

You must be logged in to reply to this topic.