which active directory cmdlet has primarysmtpaddress as a property

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.

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 = "<Unknown>"
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"

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 <some-user> -Properties ProxyAddresses | Where-Object {$_.ProxyAddresses -cmatch "SMTP"}

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 <someuser> -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.

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.