Author Posts

August 13, 2013 at 7:40 am

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.

August 13, 2013 at 8:42 am

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"

August 13, 2013 at 8:47 am

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"}

August 13, 2013 at 9:03 am

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.

August 13, 2013 at 9:14 am

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.