Link to home
Start Free TrialLog in
Avatar of K B
K BFlag for United States of America

asked on

PowerShell: Remove Email Address with .local suffix

I am attempting to take a list of users via CSV and remove all email addresses with .local in it.
Via AD PowerShell, Exchange Management Shell or Quest Shell I would like to loop through a CSV to accomplish this
Avatar of David Sankovsky
David Sankovsky
Flag of Israel image

Are we talking about an AD property or an actual Exchange email address domain? (Where the domain is *.local)

If it's the 2nd one, why would you need a CSV? you can simply spool through your entire list of users and use this PS script

foreach($i in Get-Mailbox -ResultSize Unlimited) {
  $i.EmailAddresses |
    ?{$_.AddressString -like '*@yourdomain.local'} | %{
      Set-Mailbox $i -EmailAddresses @{remove=$_}
    }
}

Open in new window


This will remove entries that has *@yourdomain.local from all mailboxes while leaving all other email addresses intact, perfect for situations where a certain OU had two domain suffixes and one was decommissioned.

Hope that helps.
Avatar of K B

ASKER

It's just a small amount of users I need to do this for. I need to leave multiple users untouched hence the CSV
I see.

In that case you might need to create a has table based on the initial data and loop through that.
However I'm afraid I'm in and out of meetings for the upcoming several hours. if no one will provide a solution till then I'll try to whip up a script for you. can you supply me with a dummy CSV for testing?
Avatar of K B

ASKER

Thank you David.  The CSV I speak of would be the user's samAccountName or UPN and that's it (I believe). Please tell me if this makes sense. I could put together a sample CSV but it would just be something like this:

John
Fred
Harry
Sam
Bryce


Or...

John@contoso.com
Fred@contoso.com
Harry@contoso.com
Sam@contoso.com
Bryce@contoso.com


----

Most of the users in the list will have a contoso.local in their proxyaddresses (AD) (or email addresses in Exchange (2010)). We also have Quest cmdlets at our disposal. AD, Exchange or Quest cmdlets would be great.

Thank you again!
K.B.
ASKER CERTIFIED SOLUTION
Avatar of David Sankovsky
David Sankovsky
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial