Cannot change PrimarySmtpAddress in powershell
Hi,
After I've used Move-Mailbox on some mailboxes from Exchange 2003 -> 2007, the primary smtp address changes from testuser@domain.com to testuser@ad.domain.com. I'd like to automate the change back to the primary smtp after the move, but the script seems
to run but nothing changes:
Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $oldprimaryaddress
Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $true
I've tried some variants of this. Latency problem?
November 14th, 2010 11:23am
Where are you setting $oldprimaryaddress?
Does it change the address if you use a literal string instead of the variable - eg:
Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $false -PrimarySmtpAddress
testuser@domain.com[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 11:33am
$oldprimaryaddress was set just before the code referred to. I've tried with
-PrimarySmtpAddress testuser@domain.com
But the change doesn't happen. Should I perhaps remove both smtp addresses and add them again? Seems like alot of work for so little.
November 14th, 2010 11:45am
Seems like it ought to work, unless testuser isn't resolving, or set-mailbox doesn't like not having the address string quoted. What do you get if you do this:
Get-Mailbox testuser
Set-mailbox testuser -EmailAddressPolicyEnabled $false -PrimarySmtpAddress
"testuser@domain.com"
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 12:02pm
This work but keeps EmailAddressPolicyEnabled disabled. When I add the 2rd line from 1. post:
Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $true
Nothing happens. For the purpose of test I also tried with:
Get-Mailbox testuser
Set-mailbox testuser -EmailAddressPolicyEnabled $false -PrimarySmtpAddress "testuser@domain.com"
Get-Mailbox testuser
Set-Mailbox testuser -EmailAddressPolicyEnabled $true
November 14th, 2010 12:11pm
There is no -EmailAddressPolicyEnabled parameter on get-mailbox, so it's not going to like
Get-mailbox testuser -EmailAddressPolicyEnabled $true
If you want to see just that property, try this:
get-mailbox testuser | select EmailAddressPolicyEnabled[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 12:19pm
And your posts are a little confusing about what you're trying to set EmalAddressPolicyEnabled to. In your original post, you indicate you're trying to set it to $false, but in subsequent posts, it's $true.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 14th, 2010 12:21pm
It was a typo - should have been set-mailbox. Using your select only outputs the value for EmailAddressPolicyEnabled.
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 12:24pm
On Sun, 14 Nov 2010 16:18:31 +0000, joebnet wrote:
>
>
>Hi,
>
>After I've used Move-Mailbox on some mailboxes from Exchange 2003 -> 2007, the primary smtp address changes from testuser@domain.com to testuser@ad.domain.com. I'd like to automate the change back to the primary smtp after the move, but the script seems
to run but nothing changes: Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $false -PrimarySmtpAddress $oldprimaryaddress
>
>Get-Mailbox testuser | Set-mailbox -EmailAddressPolicyEnabled $true
>
>I've tried some variants of this. Latency problem?
I don't understand what you're doing. If you don't want the primary
SMTP address to change, then don't enable the address policy. As soon
as you do that the policy will create the correct (according to your
policy) primary smtp address.
Maybe you need to rethink your address policies?
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
November 14th, 2010 12:26pm
Does this work any better:
Set-Mailbox testuser -EmailAddressPolicyEnabled:$true[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 14th, 2010 12:27pm
I don't understand what you're doing. If you don't want the primary
SMTP address to change, then don't enable the address policy. As soon
as you do that the policy will create the correct (according to your
policy) primary smtp address.
Maybe you need to rethink your address policies?
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
You're right. The EmailAddressPolicyEnabled must be kept disabled.
Thanks for all your help!
November 14th, 2010 12:46pm