Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Exchange 2007 - Mailbox management

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-29-2008   #1 (permalink)
Sabo, Eric
Guest


 

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
Guest


 

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]
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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]
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread