Modify alias by command Shell
Hi Guys, I've imported contacts in my exchange 2007 server... firstname.lastname@xxxxxxxxxx Exchange does not seem to like this format, see text below:"The folliwing values have invalid data : alias" firstname.lastname@xxxxxxxxxx is not valid for Alias. Valid values are: Strings formed with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may be embedded in an alias, but each one of them should be preceded and followed by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be mapped to a best-fit US-ASCII string in the email address which is generated from such an alias. I changed the alias on one of the accounts by removing '@' and everything is great. My question, is there a powershell one-liner or script that could go thorough every alias and remove the domain part of the address (everything from @)? Thx
November 30th, 2009 4:00pm

Hi, You can try with this... Get-Mailbox -ResultSize unlimited | Foreach-object {$MBx = $_; Set-Mailbox -id $_ -Alias $($MBx.split("@"))[0]} The above will split the alias with first string before "@" and second string after "@". The first string is referred as [0]. Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 4:51pm

Will it remove everything after "@" and keep only first and last name? Thx
November 30th, 2009 5:00pm

Yes. If you want to make sure yourself then i would suggest you try with couple of mailboxes first. try below... "User1", "User2" | Get-Mailbox | Foreach-object {$MBx = $_; Set-Mailbox -id $_ -Alias $($MBx.split("@"))[0]} Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 5:10pm

Oki Thank you :)
November 30th, 2009 5:11pm

I forget to say that it's for Contact and not for Mailbox... and my mailbox server is a cluster CCR... is it a problem?
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 5:16pm

Off-Course. :) Please replace Get-Mailbox with Get-MailContact. The rest will remain the same. Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
November 30th, 2009 5:31pm

I've tried it and it returned this error: Method invocation failed because [Microsoft.Exchange.Data.Directory.Management. MailContact] doesn't contain a method named 'split'. At line:1 char:110 + Get-MailContact -ResultSize unlimited | Foreach-object {$MBx = $_; Set-MailCo ntact -id $_ -Alias $($MBx.split( <<<< "@"))[0]} Cannot index into a null array. At line:1 char:117 + Get-MailContact -ResultSize unlimited | Foreach-object {$MBx = $_; Set-MailCo ntact -id $_ -Alias $($MBx.split("@"))[0 <<<< ]}
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 5:33pm

Sorry! Forgot something... "User1", "User2" | Get-Mailbox | Foreach-object {$MBx = $_.alias ; Set-Mailbox -id $_ -Alias $($MBx.split("@"))[0]} Let me know if does not work as expected. Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
November 30th, 2009 5:40pm

I'm sorry but it's still not working. Method invocation failed because [Microsoft.Exchange.Data.Directory.Management. MailContact] doesn't contain a method named 'split'. At line:1 char:116 + Get-MailContact -ResultSize unlimited | Foreach-object {$MBx = $_; Set-MailCo ntact -id $_.Alias -Alias $($MBx.split( <<<< "@"))[0]} Cannot index into a null array.
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 5:42pm

You suffixed ".Alias" at wrong place. :) "$MBx = $_.alias" is correct. Just copy and paste the command from my previous post and replace users1 and 2 with desired contacts. OR Here is the full one-liner... Get-MailContact -ResultSize unlimited | Foreach-object {$MBx = $_.alias; Set-MailContact -id $_ -Alias $($MBx.split("@"))[0]} Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
November 30th, 2009 5:56pm

Sorry but it's still not working. [PS] C:\Windows\System32>"User1" | Get-MailContact | Foreach-object {$MBx = $_.Alias; Set-MailContact -id $_ -Alias $($MBx.split("@"))[0]} WARNING: Object exchange.hamui.com/User1 has been corrupted and it is in an inconsistent state. The following validation errors have occurred: WARNING: "User1@Hamui.com" is not valid for Alias. Valid values are: Strings formed with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One more periods may be embedded in an alias, but each one of them should be preceded and followed by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will mapped to a best-fit US-ASCII string in the email address which is generate from such an alias.
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 6:06pm

Did you verify the alias is changed or not for that contact?Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
November 30th, 2009 6:11pm

Ok it worked now but it returned me just the 1 letter as alias. Before command: alias is 13December@xxxx.com After command : alias is 1
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 6:11pm

And I think it is Set-MailContact because i'm not trying to change mailbox 's alias but mail contact's alias. is it correct?
November 30th, 2009 6:16pm

ohh. Again :( sorry for that. Yes! it is Set-MailContact. Regarding the result i will test this and let you know my tomorrow morning. Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
November 30th, 2009 10:28pm

Hi Again, It is working for me. Can you give the output of below command? Please use the same ID. Execute one line at one time. $MBx = Get-MailContact -id <13December@domain.com> $MBx.Alias.Split("@") Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
December 1st, 2009 10:04am

Hi Vishal, I tried your commands: [PS] C:\Windows\System32>$MBx = Get-MailContact -id "13december@domain.com" WARNING: Object exchange.domain.com/13december has been corrupted and it is in an inconsistent state. The following validation erro have occurred: WARNING: "13december@domain.com" is not valid for Alias. Valid values are: Strings for with characters from a to z (uppercase or lowercase), digits from 0 to 9, ! $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods m be embedded in an alias, but each one of them should be preceded and follow by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be mapped to a best-fit US-ASCII string in the email address which is generated from such an alias. [PS] C:\Windows\System32>$MBx.Alias.Split("@") 13december domain.com For one user it works pretty well... but if i use Get-MailContact -ResultSize Unlimited... it doesn't work well... It split at 1 for 13december (it's an example)
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2009 11:09am

Ok. Can you check if that Alias already exist on any other object? For Example 13December. Get-MailContact -anr 13December Repeat above command for MailUser and Mailbox. See if you get anything. (I could see the actual Alias 7-9 which is not good and very short. i would suggest you should try setting FirstName.Lastname as alias on every object.) Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
December 1st, 2009 11:23am

Ok thanks!
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2009 11:38am

Vishal do you know how to import directly Active Directory contact to MailContact? I have contacts in my AD and I'd like to import them to Exchange as MailContact... do you have any idea, except the bulk file?
December 1st, 2009 11:46am

You mean contacts with Exchange Attributes? Its just we have to enable them. Enable-MailContact just fine. To know more about it type Get-Help Enable-Mailcontact -detail To script it you would need Externalemailaddress for all contact to point it to some email address or mail enable object which creates a need to have a file with object details + external email address Thanks. Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2009 12:06pm

Thanks, but this command doesn't work Get-Help | Enable-Mailcontact -detail (detail isn't known as a command)
December 1st, 2009 12:17pm

oops!! Please remove pipe sign. Get-Help Enable-Mailcontact -detail Thanks.Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2009 12:22pm

Just a question if I create a contact in AD... will it be automatically added in Exchange or should I add it?
December 1st, 2009 1:01pm

If you want it to have Exchange Attributes then you should create it from EMS or EMC. if you do so, these will get Exchange attributes. New-MailContact in PS. Thanks. Vishal Ramnani | MCITP - Exchange 2007 | MCSE Messaging | MCTS - Win 2008 Config
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2009 1:42pm

On Tue, 1-Dec-09 08:09:33 GMT, Lana_75 wrote: embedded in an alias, but each one of them should be preceded and follow by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be mapped to a best-fit US-ASCII string in the email address which is generated from such an alias. [PS] C:\Windows\System32>$MBx.Alias.Split("@") 13december domain.com For one user it works pretty well... but if i use Get-MailContact -ResultSize Unlimited... it doesn't work well... It split at 1 for>13december (it's an example) The problem may be this bit of the command: -Alias $($MBx.split("@"))[0]If the split produces an array then the subscript "[0]" refers to the1st item in the array. But if the split produces just a single result(a scalar value) the subsctipt "[0]" refers to the 1st character ofthe string "13december".To force the result of the split to always produce an array (even ifit just contains a single item, use this: @($MBx.split("@"))[0]---Rich Matheisenange MVP--- Rich Matheisen MCSE+I, Exchange MVP
December 2nd, 2009 6:13am

Hi,Please check exchange team blog, there we have fix-alias script can be downloaded. Also from the comment, we can found the following comment which just meet for your environment. So what you need to do is modify the downloaded script as Matt said and test it. Script can be found here:Exchange 2007 Scripting Corner: fix-alias http://msexchangeteam.com/archive/2007/06/15/441802.aspx"Chris said: Is there a way to pass multiple characters into the script I have a great deal of contacts with both @ and ; in the alias and am looking for a way to change both. When I run the script against either it is unable to write the new alias because it still contains an invalid character. " Matt said: Chris, To get this to work should just be a minor change. Change the following line $new = $new.replace($search,$replace) To be: $new = $new.replace($search,$replace) $new = $new.replace(;,_) Then run the script as you normally would to get it to do the replace for the @ sign. At that point it should change the @ sign as normal and then should change the ; to _ it will do all of that before it goes to run the set command. Feel free to change the _ to a character of your choice. As always please test on one user prior to running in bulk... your mileage may vary -Matt Regards,Xiu
Free Windows Admin Tool Kit Click here and download it now
December 2nd, 2009 9:34am

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

Other recent topics Other recent topics