locked
The Name property contains leading or trailing whitespace..

    Question

  • We currently have a mixed environment (Exchange 2003 & 2007). For a few AD accounts (Mailboxes on 2003), we notice the following when "Mailbox" is clicked in Exchange Management Console (Exchange 2007).

     

    WARNING: Object DOMAIN.COM/OU/USER, has been corrupted and it is in an inconsistent state. The following
    validation errors have occurred:
    WARNING: The DisplayName property contains leading or trailing whitespace, which must be removed.

     

    I searched for this on the internet and came across the follwing link and but have not tried it yet as this is for bulk users.

    http://www.exchangeninjas.com/RecipientValidation

     

    If I try the similar (for one mailbox, see below) .... it comes back with the an error:

     

    Tried the following commands:

      • get-mailbox -identity USER | Foreach { Set-Mailbox -Identity $_.Id -DisplayName $_.DisplayName.Trim() }
      • get-mailbox -identity USER | Foreach { Set-Mailbox -DisplayName $_.DisplayName.Trim() }
      • get-mailbox USER | Set-Mailbox -DisplayName $_.DisplayName.Trim()
      • Set-Mailbox -identity user -DisplayName $_.DisplayName.Trim()
      • etc etc

    Error:

    Set-Mailbox : Cannot bind argument to parameter 'Identity' because it is null.
    At line:1 char:65
    + get-mailbox -identity USER | Foreach { Set-Mailbox -Identity  <<<< $_.Id
    -DisplayName $_.DisplayName.Trim() }

     

    How do we go about removing these whitespaces. Is there a way to do this from Exchange 2007 PowerShell or do we have to use something like ADmodify..

     

    Any help in this regard would be greatly appreciated.

     

    Thanks,

    Feddie..

    Friday, August 8, 2008 3:19 PM

Answers

  • Try for one public folder first...

    get-publicfolder -identity "\Test\Path\PublicFolderName" | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()

     

    You can do same for all public folder with this command...

    get-publicfolder -identity "\" -Recurse -ResultSize Unlimited | Foreach { Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim() }

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Saturday, August 9, 2008 4:50 PM
  • Hi Mike,
    Try for one public folder first...
    Code Snippet
    Get-PublicFolder -identity "\Test\Path\PublicFolderName" | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}
    You can do same for all public folder with this command...
    Code Snippet
    Get-PublicFolder -identity "\" -Recurse -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}
    Note: This command gives error if public folder is not mail eanble, you can simply ignore that...
    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Monday, November 17, 2008 5:18 AM
  • Try this one

     

    get-mailbox -identity USER | Foreach { Set-Mailbox -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }

     

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Friday, August 8, 2008 7:56 PM
  • You need to use below command for a group

     

    Get-DistributionGroup -identity GroupName | Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim()

     

    For all groups in your environment

     

    Get-DistributionGroup | Foreach { Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Friday, October 10, 2008 7:12 PM

All replies

  • Try this one

     

    get-mailbox -identity USER | Foreach { Set-Mailbox -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }

     

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Friday, August 8, 2008 7:56 PM
  • Worked liked a champ.. Thank you so much.. I am so frustrated with myself that I didn't catch that..

     

    Feddie

    Friday, August 8, 2008 8:13 PM
  • Cool.
    Anone know how to do this against Public Folders?

    We have thousands of Foldername  with Trailing whitespace!?

    John in Tampa.
    Saturday, August 9, 2008 4:16 PM
  • Try for one public folder first...

    get-publicfolder -identity "\Test\Path\PublicFolderName" | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()

     

    You can do same for all public folder with this command...

    get-publicfolder -identity "\" -Recurse -ResultSize Unlimited | Foreach { Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim() }

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Saturday, August 9, 2008 4:50 PM
  • Thank you Amit!

    This works perfectly!
    We HAD hundreds of folders with white space.., now we have none.

    John
    Tampa, FL
    Tuesday, August 12, 2008 11:24 AM
  • My pleasure, Feddie and John

    Tuesday, August 12, 2008 1:55 PM
  • Hey guys,

     

    I am having this same issue with Groups. Would I simply change the value in the PS command from USER to GROUP?

     

    get-mailbox -identity USER | Foreach { Set-Mailbox -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }

     

    Thx for the help
    Friday, October 10, 2008 6:53 PM
  • You need to use below command for a group

     

    Get-DistributionGroup -identity GroupName | Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim()

     

    For all groups in your environment

     

    Get-DistributionGroup | Foreach { Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim() }

    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Friday, October 10, 2008 7:12 PM
  • That worked like a charm!!!!

    Thank you so much!!

    Chad
    Friday, October 10, 2008 7:19 PM
  • My problem is that several of my mail enabled public folders have spaces in the alias. I found an article on TechNet (http://technet.microsoft.com/en-us/library/bb851499.aspx) that describes how to remove spaces from mailbox aliases but what command would I use to do the same thing for public folders?

     

    Monday, November 17, 2008 4:49 AM
  • Hi Mike,
    Try for one public folder first...
    Code Snippet
    Get-PublicFolder -identity "\Test\Path\PublicFolderName" | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}
    You can do same for all public folder with this command...
    Code Snippet
    Get-PublicFolder -identity "\" -Recurse -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}
    Note: This command gives error if public folder is not mail eanble, you can simply ignore that...
    • Proposed as answer by Amit Tank Thursday, December 11, 2008 8:11 AM
    • Marked as answer by Amit Tank Thursday, December 25, 2008 8:49 AM
    Monday, November 17, 2008 5:18 AM
  •  

    You are awesome! Thanks!
    Monday, November 17, 2008 5:26 AM
  • My pleasure…

    Monday, November 17, 2008 5:30 AM
  • Hi, Amit.

    Thanks for the post. I just completed an Exch2003 to 2007 migration. I have one public folder I'm trying to run your command on and it's not working. Any ideas?

    get-publicfolder -identity "\.Confidentiality Agreements "

    returns the following result:
    Name                                         Parent Path
    .Confidentality Agreements       \
    WARNING: Object \.Confidentality Agreements  has been corrupted....
    WARNING: The Name property contains leading or trailing white space....

    I ran:
    get-publicfolder -identity "\.Confidentiality Agreements " | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()

    returns the following error:
    You cannot call a method on a null-valued expression.
    At line:1 char:119
    + get-publicfolder -identity "\.Confidentiality Agreements " | Set-publicfolder  -Identity $_.Identity -Name $_.Name.Trim( <<<< )

    Thanks.
    Tuesday, December 16, 2008 8:18 PM
  • Hi

    How do I do if I want almost the same, but with MailPublicFolder and mail alias?

    I tried with this, but it did´nt work:
    set-MailPublicFolder -identity "MailPublicFoldername" -Alias $_.Alias.Trim()

    It says "You cannot call a method on a null-valued expression".

    /Stefan
    Friday, January 2, 2009 2:58 PM
  • Hi Stefan,

    Do you want to remove leading or trailing space in mail enabled public folder alias? You need to run below command for one public folder.

    Get-MailPublicFolder -identity "MailPublicFolderName" | Set-MailPublicFolder -Identity $_.Identity -Alias $_.Alias.Trim()

    For all mail enabled public folders.

    Get-MailPublicFolder -identity "\" -Recurse -ResultSize Unlimited | Foreach { Set-MailPublicFolder -Identity $_.Identity -Alias $_.Alias.Trim() }

    Amit Tank || MVP - Exchange || MCITP - Exchange 2007 || http://ExchangeShare.WordPress.com
    Friday, January 2, 2009 8:29 PM
  • Hi

    It´s not the leading or trailing space, it´s just one or more spaces in the name, like this "Mail public Folder Name".
    I have tried your advice for a single folder, but i get the error "You cannot call a method on a null-valued expression".

    I now understand that the function trim is just for leading and trailing spaces.
    Is there a way to get rid of all the spaces?
    In Exchange 2007 it seems that spaces in the alias for a mail enabled publicfolder isn´t allowed.
    Monday, January 5, 2009 9:01 AM
  • Hi Stefan,

    To remove spaces from inside alias, try for one public folder first...

    Get-PublicFolder -identity "\Test\Path\PublicFolderName" | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}

    You can do same for all public folder with this command...

    Get-PublicFolder -identity "\" -Recurse -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}

    Note: This command gives error if public folder is not mail eanble, you can simply ignore that...

    Amit Tank || MVP - Exchange || MCITP - Exchange 2007 || http://ExchangeShare.WordPress.com
    Monday, January 5, 2009 5:35 PM
  • Hi, Amit.

    Would you be willing to look at my posted question from Dec 16? Thanks.

    Jeff
    Monday, January 5, 2009 5:43 PM
  • Hi Jeff,

    I came back from vacation and looking for pending cases one by one, can you please give me the link of your post?

    Thanks,

    Amit Tank || MVP - Exchange || MCITP - Exchange 2007 || http://ExchangeShare.WordPress.com
    Monday, January 5, 2009 5:47 PM
  • It's on this same message thread, just from Dec 16. Here it is again:

    Hi, Amit.

    Thanks for the post. I just completed an Exch2003 to 2007 migration. I have one public folder I'm trying to run your command on and it's not working. Any ideas?

    get-publicfolder -identity "\.Confidentiality Agreements "

    returns the following result:
    Name                                         Parent Path
    .Confidentality Agreements       \
    WARNING: Object \.Confidentality Agreements  has been corrupted....
    WARNING: The Name property contains leading or trailing white space....

    I ran:
    get-publicfolder -identity "\.Confidentiality Agreements " | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()

    returns the following error:
    You cannot call a method on a null-valued expression.
    At line:1 char:119
    + get-publicfolder -identity "\.Confidentiality Agreements " | Set-publicfolder  -Identity $_.Identity -Name $_.Name.Trim( <<<< )

    Thanks.
    Monday, January 5, 2009 5:50 PM
  • Hi Jeff,

    Since it is only one public folder, did you try to correct it with Public Folder Management Console (PF GUI is available in Tool Box if you are using Exchange 2007 SP1) or with PFDAVAdmin?

    Amit Tank || MVP - Exchange || MCITP - Exchange 2007 || http://ExchangeShare.WordPress.com
    Monday, January 5, 2009 6:36 PM
  • Amit,

    Thanks for the suggestions. However, the Public Folder Management Console doesn't allow PF renames, nor do Outlook or OWA.

    I can't figure out how in PFDADAdmin. I'm afraid to make a mistake and make the situation worse. 

    I think Exchange 2007 is great in nearly every way, except that the GUI lacks essential, basic functionality for a small business like mine that doesn't have the resources to learn EMS. This would have been a 5-second change in the Exchange 2003 GUI. What a frustration. 

    So, I have these tools (EMS and PFDADAdmin) that could probably make this simple change, but I can't figure out how the right syntax in either.

    I'd be grateful for any help you can offer at this point. 
    Monday, January 5, 2009 7:54 PM
  • Amit,

    I solved the problem with the following command:

    set-publicfolder -identity "\.confidentiality agreements " -name ".confidentiality agreements"

    Wow was that painful process.

    Thanks for your help and suggestions.

    Jeff
    Monday, January 5, 2009 8:15 PM
  • Hi

    When I tried on a single public folder it worked great!! (when I changed the first command to Get-MailPublicFolder, like it is in the rest of the script)

    When I run the second script for all the MailPublicFolders I get this error:

    Get-MailPublicFolder : A parameter cannot be found that matches parameter name 'Recurse'.
    At line:1 char:44
    + Get-mailPublicFolder -identity "\" -Recurse  <<<< -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set
    -MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}


    Can it be the "\" that is the problem?
    In the first script that changed a single MailPublicFolder, I used the displayname for the MailPublicFolder insted for the path.
    Maybe it works if I use "*" now?

    I don´t have any testserver for Exchange so I don´t want to run it on my productionserver if it is a bad command...

    /Stefan
    Wednesday, January 7, 2009 11:44 AM
  • Hi Stefan,

    Actually Get-MailPublicFolder doesn't have switch "Recurse" and that is why we need to use below command.

    Get-PublicFolder -identity "\" -Recurse -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}

    Explanation: Here first Get-PublicFolder gets list of all public folders recursively (because Get-MailPublicFolder doesn't haver recurse switch), pipe it to next Get-MailPublicFolder so it just filter public folders with mail enabled public folders, now pipe the output to "Where" query to filter the list of PFs which have space in alias and at last pipe it to ForEach-Object loop to remove space from the public folder alias.

    Amit Tank | MVP - Exchange | MCITP:EMA MCSA:M | http://ExchangeShare.WordPress.com
    Wednesday, January 7, 2009 12:16 PM
  • Hi Amit and thanks for your help!

    When I run your command on all my MailPublicFolders, it says for each one of them that it has an error in the Alias, but it dosn´t change it.
    When I run your other command on a single MailPublicFolder it works fine.

    The recurse command is for subdirectories if I understands it right.
    Can I search in all subdirectories with another command that works for MailPublicFolders?(so I can use Get-MailPublicFolder insted, like I do when I run it on a single folder)

    /Stefan
    Wednesday, January 7, 2009 6:00 PM
  • Hi Amit

     It seems like this command works as well:
    Get-mailPublicFolder -identity "*" | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}

    I´m not really sure anymore that your command didn´t work, maybe it did... But not for all of my MailPublicFolders, but my command didn´t either.
    It´s because there are more errors in the alias, and no changes are done.
    It seems that a dot "." isn´t a valid value, and we have a lot of MailPublicFolders with dots.

    So my question now is, can I write a command that deletes spaces and dots in the same time?

    When I try this command, I get the error below:
    Get-mailPublicFolder -identity "*" | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ",""".""")}
    The -replace operator only permits 2 elements on the right-hand side, not 3

    /Stefan
    Thursday, January 8, 2009 10:08 AM
  • This is awesome.. However, my issue with whitespace deals with the name property.. Can you help?
    Friday, January 9, 2009 8:10 PM
  • Hi Amit

    If I have error in alias, displayname and name on many mailpublicfolders and want to change it, can I do something like this?


     $folders = get-mailpublicfolder *
    foreach ($_ in $folders)
    {
    $alias = $_.alias -replace “,|\s|,|:|(|)”
    $name = $_.name -replace “,|\s|,|:|(|)”
    $displayname = $_.displayname.trim()
    set-mailpublicfolder $_ -alias $alias -name $name -displayname $displayname
    }

    /Stefan
    Tuesday, February 10, 2009 2:17 PM
  • Hi

    My biggest problem right now is how I will delete the characters () in alias for mailpublicfolders.
    I have many folders with alias like this "something (something)".

    /Stefan
    • Proposed as answer by OOSOO Thursday, March 12, 2009 7:48 PM
    Friday, February 13, 2009 4:08 PM
  • Hi All I'm about to finish migration from sbs 2003 to sbs 2008 but I'm not sure about last step remove exchange 2003 from organization, my public folder gives me an error like that, how can i find the name of the object, in the database ?

    WARNING: Object
    000000001A447390AA6611CD9BC800AA002FC45A0300657BEB49D174CA438DA4E27C390AE8BE000
    00000A83E0000 has been corrupted and it is in an inconsistent state. The
    following validation errors have occurred:
    WARNING: The Name property contains leading or trailing whitespace, which must
    be removed.
    WARNING: Object
    000000001A447390AA6611CD9BC800AA002FC45A0300657BEB49D174CA438DA4E27C390AE8BE000
    00000A8480000 has been corrupted and it is in an inconsistent state. The
    following validation errors have occurred:
    WARNING: The Name property contains leading or trailing whitespace, which must
    be removed.
    WARNING: Object
    000000001A447390AA6611CD9BC800AA002FC45A0300657BEB49D174CA438DA4E27C390AE8BE000
    00000A8490000 has been corrupted and it is in an inconsistent state. The
    following validation errors have occurred:
    WARNING: The Name property contains leading or trailing whitespace, which must
    be removed.

    what command should I use to remove that ?

    Thank's very much
    Thursday, March 12, 2009 7:53 PM
  • thanks i was run the command listed above and problem is solved thank you very much 
    Saturday, March 14, 2009 11:00 PM
  • Code Snippet
    Get-PublicFolder -identity "\" -Recurse -ResultSize Unlimited | Get-MailPublicFolder | Where {$_.Alias -like "* *"} | ForEach-Object {Set-MailPublicFolder $_.identity -Alias:($_.Alias -Replace " ","")}
    I'm having a problem wherein Outlook 2003 users can't see free/busy information. While browsing in Public Folder Management, I see that in the properties of the SCHEDULE+ FREEE BUSY folder, on the Exchange General tab, I get the same "The name property..." error. Maybe this has something to do with my problem?  The code snippet you gave above doesn't do system folders, got one that does?

    It may be totally OT or it may be significant: I can't use PFDAVAdmin. When I expand either Public Folders or System Folders I get "Could not expand https://{server}/ExAdmin/Admin/{domain}/public%20folders/non_ipm_subtree: name cannot begin with the '0' character, hexadecimal value 0x30. Line 1, position 425."
    Tuesday, May 19, 2009 7:49 PM
  • Amit,

    The problem we have is that many of our public folders have legitmate spaces in their names in addition to the leading and trailing spaces which we want to remove.  Example: when I run this command against a public folder named 'DW Migration Test <trailing spaces>, I get this error:

    [PS] C:\Documents and Settings\N81833>get-publicfolder -identity "\DW Migration
    Test" | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()
    You cannot call a method on a null-valued expression.
    At line:1 char:108
    + get-publicfolder -identity "\DW Migration Test" | Set-publicfolder -Identity
    $_.Identity -Name $_.Name.Trim( <<<< )

    get-publicfolder -identity "\Test\Path\PublicFolderName" | Set-publicfolder -Identity $_.Identity -Name $_.Name.Trim()

    We need to remove all the trailing and leading spaces from our Exchange 2000 public folders prior to migrating them to Exchange 2007 without removing the legitmate spaces. Your all public folder command removed all spaces, not just leading or trailing.

    Thanks

    Tuesday, December 1, 2009 4:50 PM
  • Our current environment is exchange server 2010 Rollup 1. We have a few Distribution Groups with leading spaces that we need to resolve in the migration process (exchange 2003 to exchange 2010). When I use the command: Get-DistributionGroup -identity "TEM - 653"| Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim()  I receive the following error:

    You cannot call a method on a null-valued expression.

    At line:1 char:123

    + Get-DistributionGroup -identity "TEM - 653"Set-DistributionGroup -Identity $_.Identity -DisplayName $_.DisplayName.Trim<<<< ()

    + CategoryInfo :InvalidOperation: (Trim:String) {}, RuntimeException

    +FullyQualifiedErrorID: InvokeMethodOnNull

     Performing a basic get command Get-DistributionGroup -identity "TEM - 653"| fl returns the properties for the object. What do you recommend?

    Thursday, July 15, 2010 4:15 PM
  • I recently asked a question in the forums regarding fixing the aliases and removing the whitespaces. 

    Are there any adverse effects when changing the alias name on public folders, mailboxes, or distribution lists?

    Is there a KB article documenting this is a safe approach?  We are beginning a 2003->2010 migration. 

    I have about 50 users and 150 public folders to fix based upon the powershell results for  {$_.Alias -like "* *"} .

    Thanks

    Thursday, July 22, 2010 7:48 PM
  •  we are getting error "The Name property contains leading or trailing whitespace, which must be removed." while add the domain in the Hub Server mail platform Exchange 2k7.

     

    Please Help, Thanks !!

    Wednesday, August 3, 2011 12:51 AM
  • I tried to run this command "Set-adobject BotheAl -DisplayName $_.DisplayName.Trim()" to remove the trailing white space on the Display name and I get this below error.

    You cannot call a method on a null-valued expression.
    At line:1 char:54
    + Set-adobject BotheAl -DisplayName $_.DisplayName.Trim <<<< ()
        + CategoryInfo          : InvalidOperation: (Trim:String) [], RuntimeExcep
       tion
        + FullyQualifiedErrorId : InvokeMethodOnNull

     

    Please help thanks,

    Wednesday, November 2, 2011 5:46 PM