Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

Thanks!

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 "alice@example.com, bob@example.com, ..." or "Alice Jones: alice@example.com, Bob Smith: bob@example.com, ..." 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
add comment

1 Answer

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. technet.microsoft.com/en-us/library/dd378937(WS.10).aspx –  pk. Sep 28 '11 at 21:00
add comment

Your Answer

 
discard

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.