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 new to powershell and Exchange so go easy on me if this comes out sounding confusing.

I need to generate a list of every possible email address in our environment (tens of thousands) that will cause the following code to error out due to an object that already exists with that email address as one of its key properties:

New-MailContact -Name $email                                  `
                -ExternalEmailAddress $email                  > $null

I have tried iterating through all entries returned from get-mailcontact, storing every email address from the 'EmailAddresses' collection, but now I believe I also need to extract all possible email addresses from User objects. I've gotten to the point where I'm thinking there's an easier, possibly one-shot way, to do this.

What is the easiest way in PS 2 to accomplish this? Is there a way to guarantee that if an email address IS in the list, New-MailContact will fail with a duplicate error, and if the email address is NOT in the list, then we are guaranteed that New-MailContact will not produce an error due to duplicates. (It may produce other errors, but not because an object already is associated with this address.)


share|improve this question
Do you want a list of all email addresses in-use in your organization, or do you want a script to find where an email address is used? Does the list need to be ",, ..." or "Alice Jones:, Bob Smith:, ..." or other? – TessellatingHeckler Sep 24 '11 at 15:27
@Tessell The items returned would be stictly email addresses - no names. I'm not looking to find an individual email address. I need a whole set (a giant one) returned. The set returned constitutes the precise list of (15,000+) email addresses that, if I were to call 'new-mailcontact -name THAT-ADDRESS -externalemailaddress THAT-ADDRESS, then the call would fail with some variant of 'proxyaddressexists' or 'memberaddressexists' or related exceptions, because some object already uses that email address. – Larold Sep 25 '11 at 4:17

I believe you could just grab every object out of your Active Directory that has a non-empty ProxyAddresses collection and then filter out for the SMTP addresses (excluding SIP and X400) -

Get-ADObject -Properties ProxyAddresses -Filter 'ProxyAddresses -gt 0' | select ProxyAddresses | %{$_.ProxyAddresses} | where{$_.ToUpper().StartsWith('SMTP:')}
share|improve this answer
get-adobject does not seem to exist on my system. Is there a special plugin or snapin I need to install? Or is this pseudo-code, where the name of the actual cmdlet is something different? – Larold Sep 28 '11 at 20:48
You need the Active Directory Administration Module for PowerShell. – pk. Sep 28 '11 at 21:00

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.