Mine is a bit more complicated, but it was written to work against Exchange
2003 first. The following function "Remove_LegacyAddress takes 2 entries, a
mailbox object and a string for the dead domain.

You'd use it something like:
$deaddomain = "exchange.taylor.k12.fl.us"
$mbxes = get-mailbox -resultsize unlimited | ?{$_.emailaddresses -match
$deaddomain}

ForEach ($mbx in $mbxes) {
   Remove_LegacyAddress $mbx $deadDomain
}

###
function Remove_LegacyAddress ($u, [string]$deadDomain) {
 if ($u -is [array]) {
  $mdn = $u[0].distinguishedname
 } else {
  $mdn = $u.distinguishedname
 }
 $mldapStr = "LDAP://"+$mdn <ldap://"+$mdn/>
 $mldap = [adsi]$mldapstr
 $pa = $mldap.proxyaddresses
 "Before: "+$U.displayname
 $pa
 $BlankAddr = @()
 foreach ($addr in $PA) {
  if ($addr -notmatch $DeadDomain ) {
   $blankaddr += $addr
  }
 }
 #Find out if NO primary SMTP
 $x = $blankaddr -match "SMTP:"
 if ($x.length -ne 0) {
  $y = $blankaddr -cmatch "SMTP:"
  if ($y.length -eq 0) {
   "No Primary SMTP"
   #$x
   $tempAddr = @()
   $a = $x[0].replace("smtp:","SMTP:")
   $tempAddr += $a
   foreach ($Addr in $blankAddr) {
    if ($addr -notmatch $a) {
     $tempaddr += $addr
    }
   }
   $blankaddr = $tempAddr
  }
 }
 Write-Host " "
 Write-Host "After:"
 if ($pa -eq $blankaddr) {
  " -> no change"
 } else {
  $blankaddr
  $mldap.proxyaddresses = $blankaddr
  $mldap.setinfo()
 }
}

#####

On Fri, Jun 12, 2009 at 7:50 AM, Campbell, Rob <
rob_campb...@centraltechnology.net> wrote:

> I need another cup of coffee.
>
> To do one mailbox:
>
> $mbx = Get-mailbox <mailbox id>
> $addrs = $mbx.emailaddresses |? {$_.smtpaddress -notlike "*@
> exchange.taylor.k12.fl.us"}
> Set-mailbox $mbx -emailaddresses $addrs
> }
>
>
>
> -----Original Message-----
> From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net]
>  Sent: Friday, June 12, 2009 9:45 AM
> To: MS-Exchange Admin Issues
> Subject: RE: Mass-Removing Alias Addresses
>
> Correction:
>
> Get-mailbox |% {
> $addrs = $_.emailaddresses |? {$_.smtpaddress -notlike "*@
> exchange.taylor.k12.fl.us"}
> Set-mailbox $_ -emailaddresses $addrs
> }
>
>
>
> To do one mailbox:
>
> $mbx = Get-mailbox
> $addrs = $mbx.emailaddresses |? {$_.smtpaddress -notlike "*@
> exchange.taylor.k12.fl.us"}
> Set-mailbox $mbx -emailaddresses $addrs
> }
>
> -----Original Message-----
> From: Campbell, Rob [mailto:rob_campb...@centraltechnology.net]
> Sent: Friday, June 12, 2009 9:36 AM
> To: MS-Exchange Admin Issues
> Subject: RE: Mass-Removing Alias Addresses
>
> You'll need to test on a sample (do the get-mailbox on a single mailbox
> first) and check the results, but this should work:
>
> Beware of wrappage
>
> Get-mailbox |% {
> $addrs = $_.emailaddresses |? {$_.smtpaddress -notlike "*@
> exchange.taylor.k12.fl.us"}
> Set-mailbox -emailaddresses $addrs
> }
>
> -----Original Message-----
> From: John Hornbuckle [mailto:john.hornbuc...@taylor.k12.fl.us]
> Sent: Friday, June 12, 2009 9:17 AM
> To: MS-Exchange Admin Issues
> Subject: Mass-Removing Alias Addresses
>
> We're an Exchange 2007 shop, and a number of our users have aliases that
> are no longer needed. For a time, we needed mail addressed to either
> u...@taylor.k12.fl.us or u...@exchange.taylor.k12.fl.us to go to the user.
> But that transition period is over, and we no longer need the @
> exchange.taylor.k12.fl.us addresses/aliases.
>
> Is there a an easy way to remove those from my users' accounts, or do I
> have to go in one by one and do it?
>
>
>
> John Hornbuckle
> MIS Department
> Taylor County School District
> 318 North Clark Street
> Perry, FL 32347
>
> www.taylor.k12.fl.us
>
>
>
>
>
> NOTICE: Florida has a broad public records law. Most written communications
> to or from this entity are public records that will be disclosed to the
> public and the media upon request. E-mail communications may be subject to
> public disclosure.
>
>
> ~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
> ~             http://www.sunbeltsoftware.com/Ninja                ~
>
>
>
> **************************************************************************************************
> Note:
> The information contained in this message may be privileged and
> confidential and
> protected from disclosure.  If the reader of this message is not the
> intended
> recipient, or an employee or agent responsible for delivering this message
> to
> the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited. If
> you
> have received this communication in error, please notify us immediately by
> replying to the message and deleting it from your computer.
>
> **************************************************************************************************
>
>
>
> ~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
> ~             http://www.sunbeltsoftware.com/Ninja                ~
>
>
>
> **************************************************************************************************
> Note:
> The information contained in this message may be privileged and
> confidential and
> protected from disclosure.  If the reader of this message is not the
> intended
> recipient, or an employee or agent responsible for delivering this message
> to
> the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited. If
> you
> have received this communication in error, please notify us immediately by
> replying to the message and deleting it from your computer.
>
> **************************************************************************************************
>
>
>
> ~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
> ~             http://www.sunbeltsoftware.com/Ninja                ~
>
>
>
> **************************************************************************************************
> Note:
> The information contained in this message may be privileged and
> confidential and
> protected from disclosure.  If the reader of this message is not the
> intended
> recipient, or an employee or agent responsible for delivering this message
> to
> the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited. If
> you
> have received this communication in error, please notify us immediately by
> replying to the message and deleting it from your computer.
>
> **************************************************************************************************
>
>
>
> ~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
> ~             http://www.sunbeltsoftware.com/Ninja                ~
>
>

~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~

Reply via email to