Piping and multivalued properties
I would like to replace the following emailaddresses with a "one liner" when I change the alias of the mailbox:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STestStudentPrimarySmtpAddress : STestStudent@mmmm.eduEmailAddresses : {smtp:SOneStudent@mmmm.edu, SMTP:STestStudent@mmmm.edu} Here is my command; I am piping in the new value of the PrimarySmtpAddress which should totally replace the current emailaddresses values: [PS] C:\>get-mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent | get-mailbox -identity:$_.identity | set-mailbox -emailaddresses:$_.primarysmtpaddressThe result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STwoTestStudentPrimarySmtpAddress : STwoTestStudent@mmmm.eduEmailAddresses : {smtp:STestStudent@mmmm.edu, SMTP:STwoTestStudent@mmmm.edu, smtp:SOneStudent@mmmm.edu}Note that the new address was "added" to the other email addresses and did not replace them.If I type in a literal it works as intended:[PS] C:\>get-mailbox -identity steststudent | set-mailbox -emailaddresses SThreeTestStudent@mmmm.edu The result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : SThreeTestStudentPrimarySmtpAddress : SThreeTestStudent@mmmm.eduEmailAddresses : {SMTP:SThreeTestStudent@mmmm.edu} The above email address (just one address) is what I am looking for but when I try to automate things with the "set-mailbox -emailaddresses:$_.primarysmtpaddress" statement the behaviour is different than simply typing the literal. I thought that maybe it was due to using the ":" in the above statement but if I change it to the following I still get the same behaviour: [PS] C:\>get-mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent | get-mailbox -identity:$_.identity | set-mailbox -emailaddresses $_.primarysmtpaddressThe Result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STwoTestStudentPrimarySmtpAddress : STwoTestStudent@mmmm.eduEmailAddresses : {smtp:SThreeTestStudent@mmmm.edu, SMTP:STwoTestStudent@mmmm.edu}So the removal of the ":" did not have a difference either. TechNet describes resetting a multivalued field but it is based upon using a variable (http://technet.microsoft.com/en-us/library/bb684908(EXCHG.80).aspx) which does not play into single line statements.Does anyone know how I could replace multiple emailaddresses with the new PrimarySmtpAddress in a "oneliner"? Also, do I need to (i.e., should I) reference the -Identity parameter on my second get-mailbox command? (If I don't do a second get-mailbox I would obtain the old value for primarySmtpAddress.)Thank you,Steve
March 15th, 2010 8:33pm

The behavior you are seeing is by design. When you change the alias, and you have an e-mail address policy that creates a new e-mail address based on the policy, the new address becomes the primary and the old one the secondary. And, for nearly all cases, this is desirable, because one doesn't want mail to bounce for some period after changing the e-mail address. To change the address, you'll need to do something like this: Get-Mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent | Set-Mailbox -EmailAddresses "SMTP:STwoTestStudent@domain.com" You could simplify it a little by assigning the alias to a variable at the beginning of the command and then building the e-mail address from it. Note that will replace all the e-mail addresses with that single SMTP address. And I haven't tested the command, so I'm not guaranteeing that it's complete or doesn't have side effects. Also, you might be able to simplify it like this: Get-Mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent -EmailAddresses "SMTP:STwoTestStudent@domain.com" but you'll need to test that yourself. -- Ed Crowley MVP"There are seldom good technological solutions to behavioral problems.". "seiden" wrote in message news:7efbc9fb-3bee-4285-97ea-7c4d0453a005... I would like to replace the following emailaddresses with a "one liner" when I change the alias of the mailbox:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STestStudentPrimarySmtpAddress : STestStudent@mmmm.eduEmailAddresses : {smtp:SOneStudent@mmmm.edu, SMTP:STestStudent@mmmm.edu} Here is my command: [PS] C:\>get-mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent | get-mailbox -idetity:$_.identity | set-mailbox -emailaddresses:$_.primarysmtpaddressThe result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STwoTestStudentPrimarySmtpAddress : STwoTestStudent@mmmm.eduEmailAddresses : {smtp:STestStudent@mmmm.edu, SMTP:STwoTestStudent@mmmm.edu, smtp:SOneStudent@mmmm.edu}Note that the new address was "added" to the other email addresses and did not replace them.If I type in a literal it works as intended:[PS] C:\>get-mailbox -identity steststudent | set-mailbox -emailaddresses SThreeTestStudent@mmmm.edu The result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : SThreeTestStudentPrimarySmtpAddress : SThreeTestStudent@mmmm.eduEmailAddresses : {SMTP:SThreeTestStudent@mmmm.edu} The above email address (just one address) is what I am looking for but when I try to automate things with the "set-mailbox -emailaddresses:$_.primarysmtpaddress" statement the behaviour is different than simply typing the literal. I thought that maybe it was due to using the ":" in the above statement but if I change it to the following I still get the same behaviour: [PS] C:\>get-mailbox -identity steststudent | set-mailbox -Alias STwoTestStudent | get-mailbox -identity:$_.identity | set-mailbox -emailaddresses $_.primarysmtpaddressThe Result:[PS] C:\>get-mailbox -identity steststudent | fl name, alias, primarysmtpaddress, emailaddresses Name : STestStudentAlias : STwoTestStudentPrimarySmtpAddress : STwoTestStudent@mmmm.eduEmailAddresses : {smtp:SThreeTestStudent@mmmm.edu, SMTP:STwoTestStudent@mmmm.edu}So the removal of the ":" did not have a difference either. TechNet describes resetting a multivalued field but it is based upon using a variable (http://technet.microsoft.com/en-us/library/bb684908(EXCHG.80).aspx) which does not play into single line statements.Does anyone know how I could replace multiple emailaddresses with the new address in a "oneliner"? Also, do I need to (i.e., should I) reference the -Identity parameter on my second get-mailbox command? (If I don't do a second get-mailbox I would obtain the old value for primarySmtpAddress.)Thank you,Steve Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2010 8:50pm

Any particular reason it has to be a "one liner" ?
March 15th, 2010 9:01pm

Hi Ed, Thanks for your reply. I noted that I was able to get the behaviour I was looking for with literals too. Unfortunately, this doesn't play into automating the script. I updated my post a little since the time you responded to it; my question essentially is "Does anyone know how I could replace multiple emailaddresses with the new PrimarySmtpAddress in a "oneliner"?"The problem is that at the beginning of the command the PrimarySmtpAddress has not been populated yet by Exchange as a result of changing the Alias field. So, it's difficult to assign a variable at that point which is why this is a bit of a struggle. And yes, our business use case is to change all addresses when a name change comes through (crazy as it seems).Steve
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2010 9:22pm

mjolinor,The commands are called from a .net program. Our current use has only one line commands like "Enable-Mailbox". You ask a good question though and I will check out if I can use more than one command at a time in .net when we construct the object. Right now our code on the .net (vb.net) side looks like this: 'Create the mailbox by invoking the Exchange Powershell command cmdResults = ems.PipelineInvoke(cmdEM, CObj(iErrors)) cmdEM holds the command passed to EMS.
March 15th, 2010 9:38pm

How does it behave if you use multiple commands, separated by the command separator (;) ?
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2010 9:45pm

We can change the .net side of the house to call multiple Cmdlets (go figure). So, I would need to set the alias in the first command and then assign a variable to the new primarysmtpaddress in the second. The third command would assign the variable to the EmailAddresses field.Sound good?
March 15th, 2010 9:57pm

If you want more control over your addressing, then you can use one command like this: Set-Mailbox -Alias address -EmailAddresses SMTP:address@domain.com -PrimarySMTPAddress SMTP:address@domain.com -EmailAddressPolicyEnabled:$False -- Ed Crowley MVP"There are seldom good technological solutions to behavioral problems.". "seiden" wrote in message news:dd0b0d5b-1815-41ee-b4d7-9c7215599ddf...We can change the .net side of the house to call multiple Cmdlets (go figure). So, I would need to set the alias in the first command and then assign a variable to the new primarysmtpaddress in the second. The third command would assign the variable to the EmailAddresses field.Sound good? Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2010 10:11pm

Should work.I think this might work, too, but I'd test it.$mbx = get-mailbox steststudent $mbx.alias = "STwoTestStudent"$mbx.emailaddresses = $mbx.primarysmtpaddress$mbx.identity | set-mailbox -instance $mbx
March 15th, 2010 10:11pm

Thanks for your much appreciated responses - Steve
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2010 10:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics