header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Removing invalid characters for alias
Last Post 06 Apr 2011 01:09 AM by ina78. 47 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Page 1 of 212 > >>
Author Messages
jsallmannUser is Offline
New Member
New Member
Posts:2
Avatar

--
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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    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
    jsallmannUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    17 Sep 2008 02:17 PM
    Thanks Shay for the input!

    I'm learning little by little
    Eric CUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    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 CUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    24 Oct 2008 07:16 AM

    I forgot to add that these are all contacts. 

    Thanks,

    Eric C.

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    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 CUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    28 Oct 2008 11:21 AM

    That command work beautifully!!!  Thanks, Shay

     

    Eric C.

    EliUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

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

    --
    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.chichioUser is Offline
    New Member
    New Member
    Posts:1
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    23 Jan 2009 12:10 AM

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    MattUser is Offline
    New Member
    New Member
    Posts:12
    Avatar

    --
    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.DUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Apr 2009 01:47 AM
    Get-MailContact -ResultSize Unlimited | where {$_.alias -match '\s'} | foreach { Set-MailContact $_ -Alias ($_.alias -replace " ") }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Jon.DUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    02 Apr 2009 08:48 AM
    Awesome, thank you Shay!
    Brian KronbergUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Jun 2009 06:02 AM
    Here's a shorter version using regex pattern to replace all illegal characters:

    ... Set-MailPublicFolder $_ -Alias ($_.alias -replace '[\s":@\\,]')

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Brian KronbergUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    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 KronbergUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

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

    --
    02 Jun 2009 08:33 AM
    What about aliases like this:

    s.h.a.y. l.e.v.y.

    Do you consider it valid even without the last dot?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Brian KronbergUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    02 Jun 2009 09:14 AM
    Yes, that is legal.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    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
    garryfrazerUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    14 Jul 2009 06:00 AM
    Get-PublicFolder -Recurse | where {$_.name -match '\s'} | foreach { Set-PublicFolder $_ -Name ($_.name -replace '\s',".") }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    garryfrazerUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    14 Jul 2009 06:36 AM
    Many thanks Shay for that.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    14 Jul 2009 06:38 AM
    Glad to help Garry!

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    webiknightUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    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 LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    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
    webiknightUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    21 Jul 2009 05:17 AM
    Thanks, I'll try it out.
    You are not authorized to post a reply.
    Page 1 of 212 > >>


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer