Quantcast
Channel: Exchange Server 2013 - Setup, Deployment, Updates, and Migration forum
Viewing all articles
Browse latest Browse all 7129

Powershell Script to Remove Secondary Addresses for Particular Domain

$
0
0

I'm trying to remove all ProxySmtp addresses for domain xyz.com in our organization.  This is not the primary SMTP address, and it is no longer an accepted domain.  

Basically I want a search of all mailboxes which have an address in the domain to be removed, then remove the addresses for that domain.  I am able to search and get results for each mailbox with an address in that domain, but when any script runs the portion to (allegedly) remove that address it does not work.  The address is still present on each mailbox.

Does anyone have a script that they have tested and can verify that it works?  The ones I've tried are all variations of this:

Get-Mailbox-result unlimited |foreach{for($i=0;$i -lt $_.EmailAddresses.Count; $i++){
        $address = $_.EmailAddresses[$i]if($address.IsPrimaryAddress-eq $false -and $address.SmtpAddress-like "*xyz.com"){
            $_.EmailAddresses.RemoveAt($i)
            $i--}}Set-Mailbox-Identity $_.Identity-EmailAddresses $_.EmailAddresses}

I first ran this with -ResultSize set to 1 (just to ensure it would work before I let it crawl every mailbox) and no luck.

I have also tried:

$adresses_dyndns =get-mailbox -ResultSize1|where{$_.EmailAddresses-like "*xyz.com*"}foreach($EmailAddress in $adresses_dyndns){for($i=$EmailAddress.EmailAddresses.Count;$i -ge 0; $i–-){

            $address = $EmailAddress.EmailAddresses[$i]if($address.SmtpAddress-like "*xyz.com*"){Write-host(" Remove smtp adress:  "+ $address.AddressString.ToString())

                  $EmailAddress.EmailAddresses.RemoveAt($i)}}

            $EmailAddress|Set-Mailbox}

Same non-result. 

Is there a reason that Exchange would refuse to remove addresses with the domain specified?


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>