bulk remove exchange alias

I had this question after viewing Exchange 2010 remove .local smtp addresses.

I modified this script to remove a test domain we have and I keep getting the following error

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

My script looks like this
Get-Mailbox | %{
    $EmailAddress = $_.EmailAddresses | ?{$_ -notlike "*mxtest*"}
    $_ | Set-Mailbox -EmailAddresses $EmailAddress
    }

When I tried this for a single user to test, it worked like a charm.  Only when I removed the username did it error.

The domain we want to get rid of is mxtest.domain.com.
Running exchange 2010 SP3
Thoughts and thanks in advance.
mgitAsked:
Who is Participating?
 
Todd NelsonSystems EngineerCommented:
I use this script to remove old proxy addresses from mailboxes--provided the addresses are not being applied with an Exchange email address policy.

$Mailboxes = Get-Mailbox -ResultSize Unlimited

$Mailboxes | foreach {
   for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
   {
      $address = $_.EmailAddresses[$i]
      if ($address.IsPrimaryAddress -eq $false -and $address.SmtpAddress -like "*DOMAIN-TO-REMOVE.com" )
      {

         Write-host($address.AddressString.ToString() | out-file C:\MailboxAddressesRemoved.txt -append )
         $_.EmailAddresses.RemoveAt($i)
         $i--
      }
   }
   Set-Mailbox -Identity $_.Identity -EmailAddresses $_.EmailAddresses
}

Open in new window

0
 
MaheshArchitectCommented:
try below

Get-Mailbox | %{
     $EmailAddress = $_.EmailAddresses | ?{$_ -notlike "*mxtest*"} | Set-Mailbox -EmailAddresses $EmailAddress
     }

Open in new window

I have removed extra pipeline
0
 
mgitAuthor Commented:
I'm afraid that didn't work.

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Invoke-Command : Cannot write input as there are no more running pipelines
At C:\Users\robertferguson\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\server1.domain.com\server1.domain.com.psm1:50548 char:29
+             $scriptCmd = { & <<<<  $script:InvokeCommand `
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
    + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand

Thanks for replying so quickly..
0
 
Aaron GuilmetteTechnology Solutions ProfessionalCommented:
0
 
mgitAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.