Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am 3-to-4 weeks new to powershell and using it to interact with Active Directory / Exchange. (Both of which I'm also very new to.)

I've tried reading this page: but I'm a bit overwhelmed by all of the information, probably because I'm exhausted.

Here's what I'm trying to do. Within my code, I want to take an email address as an input string, and create a mail contact (New-MailContact) with the -ExternalEmailAddress parameter set to this string. This is trivially easy. BUT, if an object in AD already exists with this address, it won't let me create the mail contact. So, before the creation attempt, I need to determine if the call to create-mailcontact will produce an error. (The reason I need to detect this is because if this condition is occurring, I need to run a whole bunch of other commands and logic.)

What I have been trying to do is collect all 'WindowsEmailAddress' properties from the objects returned by these calls:

get-user -resultSize unlimited
get-mailcontact -resultSize unlimited

I then look in these results (I convert them to a nice in-memory hash table where the keys are the lowercase email address strings) to see if the email address I'm going to set up a contact for already exists. For most email addresses that are users in our AD domain, this works great.

Unfortunately, there are a few that don't appear in either of these lists, but I still can't create the mail contact because it says the address already exists:

The proxy address "" is already being used by
" Contacts/Some User Name". Please choose another proxy
  + CategoryInfo          : NotSpecified: ( [New-MailContact], ProxyAddressExistsException
  + FullyQualifiedErrorId : 6580586A,Microsoft.Exchange.Management.Recipient Tasks.NewMailContact

I am a bit afraid to iterate through the list returned by get-recipient... is that what I need to do? I was thinking there is probably an easy way to accomplish this I haven't figured out yet.

Important note: There are about 20-30 addresses, all returning this type of error. HOWEVER, when you look above and see 'Exchange Contacts' in the error, well, that portion of the string is completely different from one faulty email address to the next. Not sure if that's relevant. Please feel free to set me straight on anything I'm not understanding. Thanks!

share|improve this question

Note that the "mail" attribute is not the only place where an email address may be located. There is also a multi-valued attribute "proxyAddresses", where additional email addresses may be assigned to an object.

Someone has created a script here: (requires the free Quest AD cmdlet)

    Param (
        HelpMessage="Enter SMTP address to search for in Active-Directory."
Function Get-ProxyAddresses ([string]$Address){
$objAD = $null
$objAD = Get-QADObject -LdapFilter "(proxyAddresses=*$Address*)" -IncludeAllProperties -SizeLimit 0 -ErrorAction SilentlyContinue
Write-Output $objAD
}#Close Function
#Validate Quest PSSnapin is loaded
Add-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
#Run Function to search AD for SMTP address
$Results = $null
$Results = Get-ProxyAddresses -Address $objSMTP | Select-Object Name,DisplayName,ObjectClass,Email,AccountisDisabled,AccountisLockedOut,MailNickName,LegacyExchangeDN -ErrorAction SilentlyContinue
IF($Results -eq $null){
Write-Host ""
Write-Host "No Object Found with .attribute[proxyAddress] containing $objSMTP."}
Else{$Results | Format-List *}
share|improve this answer
Thanks for the post - I'm going to give this a shot! – Larold Sep 22 '11 at 15:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.