Identify primary SMTP Address from Active Directory with PowerShell

Hello,

Usually, PowerShell is case insensitive, but, if you need it to be, you can force your operators to be case sensitive.In a Exchange/Office 365 environment, mailboxes addresses aliases are stored in the “ProxyAddresses” attributes in the Active Directory users. You can distinguished the primary address from the aliases with the case. Indeed, the primary SMTP address will start with “SMTP:” in caps, and the aliases will start with “smtp:” in small caps.

If you look at :

Get-Help *operators*

You’ll learn about case sensitive operators such as “clike”, this is the one we’ll use today.

First, we need to get the ProxyAddresses attribute from AD :

Get-ADUser -Identity emmanuel.demilliere -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses

Identify-Primary-SMTP-Address-From-AD-1

Then, we need to identify the one that starts with “SMTP:” :

Get-ADUser -Identity emmanuel.demilliere -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike "SMTP:*"}

We used the “clike” operators, wich is case sensitive :

Identify-Primary-SMTP-Address-From-AD-2

And here we go !

Leave a Reply