Vishal Ramnani
 New Member Posts:68

 |
| 18 Sep 2009 01:46 AM |
|
Hey Guys
I am trying to edit a mailbox's email addresses (proxyAddressCollection). when adding a new SMTP address in this field it gets set as Primary. how to make other one Primary in the Variable itself then set in the mailbox?
Here is what i am trying...
$mb = Get-Mailbox -id "User" $mb.emailaddresses.Add("SMTP:newemailID") $mb.emailaddresses.makeprimary(SMTP:oldemailID")
It gives me an error below.
Cannot convert argument "0", with value: "SMTP:oldemailID", for "MakePrimary" to type "System.Int32": "Cannot convert value "SMTP:OldEmailID" to type "System.Int32". Error: "Input string was not in a correct format."" At line:1 char:31 + $mb.emailaddresses.MakePrimary <<<< ("SMTP:OldemailID")
Any Ideas...
Thanks in advance.
|
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
Vishal Ramnani
 New Member Posts:68

 |
| 20 Sep 2009 05:52 AM |
|
is it possible guys?? |
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|
Mike Pfeiffer
 New Member Posts:28

 |
| 20 Sep 2009 04:12 PM |
|
It's giving you an error becuase you are trying to pass a string to the method, and it's expecting an integer. Use the index of the email address in the $mb.emailaddresses array:
$mb.emailaddresses.makeprimary(0)
Don't forget when you are done you still need to use set-mailbox to set the email address values:
Set-Mailbox username -EmailAddresses $mb.emailaddresses
Another thing to mention...you can pass an array of emailaddresses to Set-Mailbox -EmailAddress and by default it will set the first address as the primary, for example:
Set-Mailbox username -EmailAddresses "user@domain.local","username@domain.local"
or...
This would add an additional email address leaving the existing primary address intact:
$user = Get-Mailbox username $user.emailddresses+="user@domain.com" Set-Mailbox $user -EmailAddresses $user.emailaddresses
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 20 Sep 2009 11:54 PM |
|
You can simply do the following, the new PrimarySmtpAddress sets the email as the primary address (you may have to disable EmailAddressPolicyEnabled): Get-Mailbox user1 | Set-Mailbox -PrimarySmtpAddress user1@domain.com -EmailAddressPolicyEnabled $false
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
Vishal Ramnani
 New Member Posts:68

 |
| 22 Sep 2009 12:33 AM |
|
Thanks Mike, That worked.
To add here for others...
We can find the index of the values in the this array as below.
$mb.emailaddresses.Indexof("value in ProxyAddressString")
Correct me if i am wrong here.
|
|
Vishal Ramnani MCITP - Exchange 2007, MCSE Messaging, MCTS - Win 2008 Config |
|
|