5

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!

2
  • 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 "[email protected], [email protected], ..." or "Alice Jones: [email protected], Bob Smith: [email protected], ..." or other? Sep 24, 2011 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, 2011 at 4:17

1 Answer 1

1

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:')}
2
  • 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, 2011 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, 2011 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .