jsallmann
 New Member Posts:2

 |
| 15 Sep 2008 05:19 PM |
|
Hello group,
I think I understand how to remove whitespace in all Exchange 2007 public folder alias;
get-publicfolder -identity "\" -Recurse -ResultSize Unlimited | Foreach { Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim() }
My question is how do I remove both whitespace and another invalid character such as a comma ,
For example if my public folder alias was;
glenn, tom 2001
and i wanted it to be;
glenntom2001
Thanks for any help.
Joe |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 15 Sep 2008 10:57 PM |
|
This will remove any whitespace or commas: get-publicfolder -identity "\" -Recurse -ResultSize Unlimited | Foreach { Set-publicfolder -Identity $_.Identity -Name ($_.Name -replace ",|\s") } |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
jsallmann
 New Member Posts:2

 |
| 17 Sep 2008 02:17 PM |
|
Thanks Shay for the input! I'm learning little by little |
|
|
|
|
Eric C
 New Member Posts:3

 |
| 24 Oct 2008 07:13 AM |
|
I need a command to remove all the invalid characters in the alias for Exchange 2007. I have several thousand aliases that are similiar to Smith, Joe D. There are multiple invalid characters in them. Any help would be appreciated. Thanks,
Eric C. |
|
|
|
|
Eric C
 New Member Posts:3

 |
| 24 Oct 2008 07:16 AM |
|
I forgot to add that these are all contacts.
Thanks,
Eric C. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 24 Oct 2008 07:32 AM |
|
It depends what do you consider as invalid characters. The following removes dots, spaces and commas. So "Smith, Joe D." is going to be: SmithJoeD PS > Get-MailContact -ResultSize unlimited | foreach {$_.alias = $_.alias -replace '\s|,|\.'; $_} | Set-MailContact |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
Eric C
 New Member Posts:3

 |
| 28 Oct 2008 11:21 AM |
|
That command work beautifully!!! Thanks, Shay
Eric C. |
|
|
|
|
Eli
 New Member Posts:2

 |
| 30 Dec 2008 11:46 AM |
|
What is the powershell commands to view white space on different mailbox databases? |
|
|
|
|
Eli
 New Member Posts:2

 |
| 30 Dec 2008 11:49 AM |
|
What is the powershell comman for identifyting white space on each of the mailbox databases and how to I port the info to a csv file. |
|
|
|
|
mr.chichio
 New Member Posts:1

 |
| 22 Jan 2009 01:00 PM |
|
try this.. start-transcript "filepath.txt" get-public folders etc.. etc.. stop-transcript but I don't know how to catch the exception (.NET?) HTH Andrea |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Matt
 New Member Posts:12

 |
| 06 Mar 2009 11:42 AM |
|
When I try to run a modified version of this command, (and the original command, for that matter):
Get-MailContact -ResultSize Unlimited | Foreach {$_.alias = $_.alias -replace ‘\.’; $_} | Set-MailContact -whatif
I receive the following errors (one for each MailContact, all have similiar verbage to below):
Exception setting "Alias": ""PGR-7075996570(SDL-Eureka)" is not valid for Alias . Valid values are: Strings formed with characters from a to z (uppercase or lo wercase), 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. Unico de characters from U+00A1 to U+00FF are also valid in an alias, but they will b e mapped to a best-fit US-ASCII string in the email address which is generated from such an alias." At line:1 char:53 + Get-MailContact -ResultSize Unlimited | Foreach {$_.a <<<< lias = $_.alias -r eplace `\.'; $_} | Set-MailContact -whatif Set-MailContact : ".PGR-7075996570(SDL-Eureka)" is not valid for Alias. Valid v alues 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 b e preceded and followed by at least one of the other characters. Unicode charac ters 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. At line:1 char:106 + Get-MailContact -ResultSize Unlimited | Foreach {$_.alias = $_.alias -replace `\.'; $_} | Set-MailContact <<<< -whatif WARNING: Object anyone.anywhere.com/SDL-GLB/Contacts/.PGR-7075996570 (SDL-Eureka) has been corrupted and it is in an inconsistent state. The following validation errors have occurred: WARNING: ".PGR-7075996570(SDL-Eureka)" 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 would think that the command should still work for me, as I'm only removing qualifying characters from the script. |
|
|
|
|
Jon.D
 New Member Posts:3

 |
| 01 Apr 2009 12:57 PM |
|
I would like to know how to replace the spaces with periods.. is that possible? So if I had Joe R Smith it would end up as Joe.R.Smith
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Jon.D
 New Member Posts:3

 |
| 02 Apr 2009 08:48 AM |
|
Awesome, thank you Shay! |
|
|
|
|
Brian Kronberg
 New Member Posts:4

 |
| 02 Jun 2009 05:52 AM |
|
I just wanted to add this for the next searcher. We had the problem that the alias of mail enabled public folders would have more than one illegal character. You can do multiple replaces by just adding in multiple "-replace" entries. I am also using a '\s' which matches any whitespace character and am "escaping" (using a backslash character) on the parenthesis. Get-MailPublicFolder -ResultSize Unlimited | where {$_.alias -match '\s'} | foreach {Set-MailPublicFolder $_ -Alias ($_.alias -replace '\s' -replace '"' -replace ':' -replace '@' -replace '\(' -replace '\)' -replace ',')} |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Brian Kronberg
 New Member Posts:4

 |
| 02 Jun 2009 07:31 AM |
|
That is way easier, but here is a tougher one that I cannot figure out. How to I also include in that simplified replace an alias that ends with a period taking into account the other replacements? |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 02 Jun 2009 07:49 AM |
|
the dot (".") is a regex meta character, you need to escape it (the last two characters in the pattern): ... Set-MailPublicFolder $_ -Alias ($_.alias -replace '[\s":@\\,\.]') This will replace any dot in the alias? did you want to replace just the ones that ENDS with a dot? |
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
Brian Kronberg
 New Member Posts:4

 |
| 02 Jun 2009 07:53 AM |
|
Yes, a period is valid except as the last character. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Brian Kronberg
 New Member Posts:4

 |
| 02 Jun 2009 09:14 AM |
|
Yes, that is legal. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 02 Jun 2009 10:24 PM |
|
I would try with two replces: -alias ($_.alias -replace '[\s":@\\,]' -replace '(?<=.+)\.') The first removes every illegal char (not including dots) and the second removes the dot if exists from the end of the string.
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
garryfrazer
 New Member Posts:2

 |
| 14 Jul 2009 05:40 AM |
|
I would like to know the syntax for replacing all "spaces" in public folder names/aliases with "." Many thanks to all in advance for their help on this. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
garryfrazer
 New Member Posts:2

 |
| 14 Jul 2009 06:36 AM |
|
Many thanks Shay for that. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
webiknight
 New Member Posts:7

 |
| 20 Jul 2009 10:37 PM |
|
Thanks for all the info above. I am also trying to remove the spaces in the Alias but would like to test the script by running it against a specific PF. I get the Warning below. Does anyone know why it is happening? [PS] U:\>get-publicfolder -identity "\xxxxx\xxxxxx\xxxxx\3500 - IS Department" -Recurse -ResultSize Unlimited | Foreach { Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim() } WARNING: The command completed successfully but no settings of '\xxxxx\xxxxxx\xxxxx\3500 - IS Department' have been modified. Thanks for the help. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 20 Jul 2009 11:31 PM |
|
As the description states, the command runs to completion but no changes applied. The Trim method removes leading and trailing spaces from a string NOT in the middle of a string, you should use replace instead.
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
webiknight
 New Member Posts:7

 |
| 21 Jul 2009 05:17 AM |
|
Thanks, I'll try it out. |
|
|
|
|