Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Exchange 2007 - Mailbox management

Reply
 
Old 01-29-2008   #1 (permalink)
Sabo, Eric


 
 

Exchange 2007 - Mailbox management

I have an Exchange 2007 question, we want to delete all email address except
for the "PrimarySmtpAddress" under a user account. We know how to Uncheck
"automatically update email address based on recipient policy.



If you do a "get-mailbox XXXXX | fl" this list all information about the
account



The variable we want to change is "EmailAddresses" within the mailbox.



We basically want to delete all "emailaddresses" except for the
"PrimarySMTPAddress"



Thanks in advance,

Eric Sabo


My System SpecsSystem Spec
Old 01-29-2008   #2 (permalink)
Shay Levi


 
 

Re: Exchange 2007 - Mailbox management


Try:

$user = "test"
$mailbox = Get-Mailbox $user

$mailbox.EmailAddresses | foreach {
if (!$_.IsPrimaryAddress -and ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses
-= $_}
}

$mailbox | set-mailbox



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I have an Exchange 2007 question, we want to delete all email address
> except for the "PrimarySmtpAddress" under a user account. We know how
> to Uncheck "automatically update email address based on recipient
> policy.
>
> If you do a "get-mailbox XXXXX | fl" this list all information about
> the account
>
> The variable we want to change is "EmailAddresses" within the mailbox.
>
> We basically want to delete all "emailaddresses" except for the
> "PrimarySMTPAddress"
>
> Thanks in advance,
>
> Eric Sabo
>

My System SpecsSystem Spec
Old 01-29-2008   #3 (permalink)
Marco Shaw [MVP]


 
 

Re: Exchange 2007 - Mailbox management

Sabo, Eric wrote:
Quote:

> I have an Exchange 2007 question, we want to delete all email address
> except for the "PrimarySmtpAddress" under a user account. We know how
> to Uncheck "automatically update email address based on recipient policy.
>
>
>
> If you do a "get-mailbox XXXXX | fl" this list all information about
> the account
>
>
>
> The variable we want to change is "EmailAddresses" within the mailbox.
>
>
>
> We basically want to delete all "emailaddresses" except for the
> "PrimarySMTPAddress"
>
>
>
> Thanks in advance,
>
> Eric Sabo
>
I don't know if this helps with that property:
http://groups.google.com/group/micro...e24530e1835b3c

Willing to install/try or already have the Quest AD cmdlets?

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 01-29-2008   #4 (permalink)
Sabo, Eric


 
 

Re: Exchange 2007 - Mailbox management

Shay,

Thanks for the reply.

So you are saying that this will delete all email addresses except for the
primary adddress?


"Shay Levi" <no@xxxxxx> wrote in message
news:8766a9441c3118ca3090529d417c@xxxxxx
Quote:

>
> Try:
>
> $user = "test"
> $mailbox = Get-Mailbox $user
>
> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
> }
>
> $mailbox | set-mailbox
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> I have an Exchange 2007 question, we want to delete all email address
>> except for the "PrimarySmtpAddress" under a user account. We know how
>> to Uncheck "automatically update email address based on recipient
>> policy.
>>
>> If you do a "get-mailbox XXXXX | fl" this list all information about
>> the account
>>
>> The variable we want to change is "EmailAddresses" within the mailbox.
>>
>> We basically want to delete all "emailaddresses" except for the
>> "PrimarySMTPAddress"
>>
>> Thanks in advance,
>>
>> Eric Sabo
>>
>
>

My System SpecsSystem Spec
Old 01-29-2008   #5 (permalink)
Shay Levi


 
 

Re: Exchange 2007 - Mailbox management

Yup,

Make sure to test it, don't take anything for granted
Basically, I've created a test user, added some email addresses to it and
run the code.

I suggest to log each user's addresses before and after the modification
process.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Shay,
>
> Thanks for the reply.
>
> So you are saying that this will delete all email addresses except for
> the primary adddress?
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a9441c3118ca3090529d417c@xxxxxx
>
Quote:

>> Try:
>>
>> $user = "test"
>> $mailbox = Get-Mailbox $user
>> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
>> }
>> $mailbox | set-mailbox
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I have an Exchange 2007 question, we want to delete all email
>>> address except for the "PrimarySmtpAddress" under a user account.
>>> We know how to Uncheck "automatically update email address based on
>>> recipient policy.
>>>
>>> If you do a "get-mailbox XXXXX | fl" this list all information
>>> about the account
>>>
>>> The variable we want to change is "EmailAddresses" within the
>>> mailbox.
>>>
>>> We basically want to delete all "emailaddresses" except for the
>>> "PrimarySMTPAddress"
>>>
>>> Thanks in advance,
>>>
>>> Eric Sabo
>>>

My System SpecsSystem Spec
Old 01-29-2008   #6 (permalink)
Sabo, Eric


 
 

Re: Exchange 2007 - Mailbox management

Ran the script and that does not remove any of them.

Is there a way I can clear all but the primary email address?

"Shay Levi" <no@xxxxxx> wrote in message
news:8766a9441c3118ca3090529d417c@xxxxxx
Quote:

>
> Try:
>
> $user = "test"
> $mailbox = Get-Mailbox $user
>
> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
> }
>
> $mailbox | set-mailbox
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> I have an Exchange 2007 question, we want to delete all email address
>> except for the "PrimarySmtpAddress" under a user account. We know how
>> to Uncheck "automatically update email address based on recipient
>> policy.
>>
>> If you do a "get-mailbox XXXXX | fl" this list all information about
>> the account
>>
>> The variable we want to change is "EmailAddresses" within the mailbox.
>>
>> We basically want to delete all "emailaddresses" except for the
>> "PrimarySMTPAddress"
>>
>> Thanks in advance,
>>
>> Eric Sabo
>>
>
>

My System SpecsSystem Spec
Old 01-29-2008   #7 (permalink)
Shay Levi


 
 

Re: Exchange 2007 - Mailbox management


Try this:

$user = "test"
$mailbox = Get-Mailbox $user

## EmailAddresses before
# $mailbox.EmailAddresses

$mailbox.EmailAddresses | where {!$_.IsPrimaryAddress -and ($_.PrefixString
-eq "SMTP")} | foreach {$mailbox.EmailAddresses -= $_.SmtpAddress}
$mailbox | set-mailbox

## EmailAddresses after
# $mailbox.EmailAddresses




-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Ran the script and that does not remove any of them.
>
> Is there a way I can clear all but the primary email address?
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a9441c3118ca3090529d417c@xxxxxx
>
Quote:

>> Try:
>>
>> $user = "test"
>> $mailbox = Get-Mailbox $user
>> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
>> }
>> $mailbox | set-mailbox
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I have an Exchange 2007 question, we want to delete all email
>>> address except for the "PrimarySmtpAddress" under a user account.
>>> We know how to Uncheck "automatically update email address based on
>>> recipient policy.
>>>
>>> If you do a "get-mailbox XXXXX | fl" this list all information
>>> about the account
>>>
>>> The variable we want to change is "EmailAddresses" within the
>>> mailbox.
>>>
>>> We basically want to delete all "emailaddresses" except for the
>>> "PrimarySMTPAddress"
>>>
>>> Thanks in advance,
>>>
>>> Eric Sabo
>>>

My System SpecsSystem Spec
Old 01-29-2008   #8 (permalink)
Jeffery Hicks [MVP]


 
 

Re: Exchange 2007 - Mailbox management

I think I answered this problem in another forum and I don't think you can
do it with the Exchange 2007 cmdlets. You can modify the user with the
Quest AD set-qaduser cmdlet though. Or use VBScript.
--
Jeffery Hicks MCSE, MCSA, MCT
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org
http://jdhitsolutions.blogspot.com

Now Available: WSH and VBScript Core: TFM
Now Available: Windows PowerShell v1.0: TFM 2nd Ed.


"Sabo, Eric" <sabo_e@xxxxxx> wrote in message
news:OEGJhqnYIHA.220@xxxxxx
Quote:

> Ran the script and that does not remove any of them.
>
> Is there a way I can clear all but the primary email address?
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a9441c3118ca3090529d417c@xxxxxx
Quote:

>>
>> Try:
>>
>> $user = "test"
>> $mailbox = Get-Mailbox $user
>>
>> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
>> }
>>
>> $mailbox | set-mailbox
>>
>>
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
>>
Quote:

>>> I have an Exchange 2007 question, we want to delete all email address
>>> except for the "PrimarySmtpAddress" under a user account. We know how
>>> to Uncheck "automatically update email address based on recipient
>>> policy.
>>>
>>> If you do a "get-mailbox XXXXX | fl" this list all information about
>>> the account
>>>
>>> The variable we want to change is "EmailAddresses" within the mailbox.
>>>
>>> We basically want to delete all "emailaddresses" except for the
>>> "PrimarySMTPAddress"
>>>
>>> Thanks in advance,
>>>
>>> Eric Sabo
>>>
>>
>>
>
>
My System SpecsSystem Spec
Old 01-29-2008   #9 (permalink)
Karl Mitschke


 
 

Re: Exchange 2007 - Mailbox management

Hello Eric,
Quote:

> Ran the script and that does not remove any of them.
>
> Is there a way I can clear all but the primary email address?
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a9441c3118ca3090529d417c@xxxxxx
>
Quote:

>> Try:
>>
>> $user = "test"
>> $mailbox = Get-Mailbox $user
>> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
>> }
>> $mailbox | set-mailbox
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> I have an Exchange 2007 question, we want to delete all email
>>> address except for the "PrimarySmtpAddress" under a user account.
>>> We know how to Uncheck "automatically update email address based on
>>> recipient policy.
>>>
>>> If you do a "get-mailbox XXXXX | fl" this list all information
>>> about the account
>>>
>>> The variable we want to change is "EmailAddresses" within the
>>> mailbox.
>>>
>>> We basically want to delete all "emailaddresses" except for the
>>> "PrimarySMTPAddress"
>>>
>>> Thanks in advance,
>>>
>>> Eric Sabo

Eric;

You may have stumbled over line wraps in Shay's example, so try this one,
removing the @ from each line.
(If the line doesn't start with an @, it is part of the previous line.)

@$mailbox = Get-Mailbox $user
@$addresses = $mailbox.EmailAddresses
@$beforecount = $addresses.count
@$mailbox.EmailAddresses | foreach {
@if (!$_.IsPrimaryAddress -and ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses
-= $_}} | set-mailbox
@$addresses = $mailbox.EmailAddresses
@$aftercount = $addresses.count
@write-host "There were $beforecount email addresses"
@write-host "There is now $aftercount email address"


Karl


My System SpecsSystem Spec
Old 01-29-2008   #10 (permalink)
Shay Levi


 
 

Re: Exchange 2007 - Mailbox management

FYI, the PowerShell version is working.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Thanks everyone for their input, we current have a vbscript that does
> this I was just wondering if it could be done with powershell
>
> Thanks again!
>
> "Karl Mitschke" <kmitschke@xxxxxx> wrote in message
> news:7063857f26c888ca307bffc2a207@xxxxxx
>
Quote:

>> Hello Eric,
>>
Quote:

>>> Ran the script and that does not remove any of them.
>>>
>>> Is there a way I can clear all but the primary email address?
>>>
>>> "Shay Levi" <no@xxxxxx> wrote in message
>>> news:8766a9441c3118ca3090529d417c@xxxxxx
>>>> Try:
>>>>
>>>> $user = "test"
>>>> $mailbox = Get-Mailbox $user
>>>> $mailbox.EmailAddresses | foreach { if (!$_.IsPrimaryAddress -and
>>>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}
>>>> }
>>>> $mailbox | set-mailbox
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>>> I have an Exchange 2007 question, we want to delete all email
>>>>> address except for the "PrimarySmtpAddress" under a user account.
>>>>> We know how to Uncheck "automatically update email address based
>>>>> on recipient policy.
>>>>>
>>>>> If you do a "get-mailbox XXXXX | fl" this list all information
>>>>> about the account
>>>>>
>>>>> The variable we want to change is "EmailAddresses" within the
>>>>> mailbox.
>>>>>
>>>>> We basically want to delete all "emailaddresses" except for the
>>>>> "PrimarySMTPAddress"
>>>>>
>>>>> Thanks in advance,
>>>>>
>>>>> Eric Sabo
>>>>>
>> Eric;
>>
>> You may have stumbled over line wraps in Shay's example, so try this
>> one,
>> removing the @ from each line.
>> (If the line doesn't start with an @, it is part of the previous
>> line.)
>> @$mailbox = Get-Mailbox $user
>> @$addresses = $mailbox.EmailAddresses
>> @$beforecount = $addresses.count
>> @$mailbox.EmailAddresses | foreach { @if (!$_.IsPrimaryAddress -and
>> ($_.PrefixString -eq "SMTP")) {$mailbox.EmailAddresses -= $_}} |
>> set-mailbox
>> @$addresses = $mailbox.EmailAddresses
>> @$aftercount = $addresses.count
>> @write-host "There were $beforecount email addresses"
>> @write-host "There is now $aftercount email address"
>> Karl
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Exchange 2007 Remove Mailbox after AD deletion .NET General
Deleting A Folder In A User Mailbox In Exchange 2007 PowerShell
Exchange 2007: cross org mailbox migration bulk from csv file PowerShell
Exchange 2007 Bulk Mailbox Creation - Password? PowerShell
Creating a new mailbox on Exchange 2007 PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46