none
enable-mailbox: leading or trailing whitespace RRS feed

  • Question

  • When I run enable-mailbox it errors out with this: The property value is invalid. The value can't contain leading or trailing whitespace.

    Get-user gets me this:

    WARNING: The object domainname/OUS/username  has been corrupted, and it's in an inconsistent state.
     The following validation errors happened:
    WARNING: The property value is invalid. The value can't contain leading or trailing whitespace.

     

    When I look in AD users and computers MMC I don't see any whitespaces.

    How to fix this whitespace or invalid characters for one specific user and a group of users if necessary?

    Thanks

    Friday, December 16, 2011 7:25 PM

Answers

  • I used ADSIEdit to find out that cn is the culprit. It has a space. Yes, thru' CSVDE I do mass imports and causes this issue. I should do more checking in excel before I run it.

     

    I then used:

     set-user <username> -name "FirstName LastName" 

     

    All fixed ;)

     

    • Edited by Mr.Kris Friday, December 16, 2011 10:58 PM
    • Marked as answer by Evan LiuModerator Sunday, December 25, 2011 10:50 AM
    Friday, December 16, 2011 10:40 PM

All replies

  • On Fri, 16 Dec 2011 19:25:32 +0000, Mr.Kris wrote:
     
    >When I run enable-mailbox it errors out with this: The property value is invalid. The value can't contain leading or trailing whitespace.
    >
    >Get-user gets me this:
    >
    >WARNING: The object domainname/OUS/username has been corrupted, and it's in an inconsistent state. The following validation errors happened: WARNING: The property value is invalid. The value can't contain leading or trailing whitespace.
    >
    >
    >
    >When I look in AD users and computers MMC I don't see any whitespaces.
    >
    >How to fix this whitespace or invalid characters for one specific user and a group of users if necessary?
     
    First you have to identify what property it is that has the
    leading/trailing whitespace. Is it the sAMAccountname?
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Friday, December 16, 2011 7:54 PM
  • That I don't know. Can you please help me on that?
    Friday, December 16, 2011 9:08 PM
  • On Fri, 16 Dec 2011 21:08:51 +0000, Mr.Kris wrote:
     
    >That I don't know. Can you please help me on that?
     
    Try running get-user with the -verbose switch on one user and see it
    it coughs up any more information.
     
    These are the properties I'd look at first:
    firstname
    lastname
    displayname
    initials
    name
    samaccountname
    userprincipalname
     
    Knowing how the AD user object was created would help, too. I don't
    think that any of the powershell cmdlets would allow an invalid value
    to be inserted. The same goes for the ADUC. But any custom coded
    creation of the AD user that didn't verify that the data was correct
    could certainly accomplish that misdeed.
     
    Things like CSVDE, LDIFDE, ADSIEDIT, ADSI, etc. are all ways that can
    introduce errors.
     
    Something like this might point out the problem:
     
    $u=get-user <USERNAME>
    $props = "firstname",
    "lastname",
    "displayname",
    "initials",
    "name",
    "samaccountname",
    "userprincipalname"
    $props | foreach{
    if ($u.$_.trim() -ne $u.$_)
    {
    write-host "Property $_ has leading or trailing spaces"
    }
    }
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Friday, December 16, 2011 9:59 PM
  • I used ADSIEdit to find out that cn is the culprit. It has a space. Yes, thru' CSVDE I do mass imports and causes this issue. I should do more checking in excel before I run it.

     

    I then used:

     set-user <username> -name "FirstName LastName" 

     

    All fixed ;)

     

    • Edited by Mr.Kris Friday, December 16, 2011 10:58 PM
    • Marked as answer by Evan LiuModerator Sunday, December 25, 2011 10:50 AM
    Friday, December 16, 2011 10:40 PM
  • On Fri, 16 Dec 2011 22:40:46 +0000, Mr.Kris wrote:
     
    >I used ADSIEdit to find out that cn is the culprit. It has a space. Yes, thru' CSVDE I do mass imports and causes this issue. I should do more checking in excel before I run it.
     
    You can use a CSV file as a data source. Import it into a powershell
    script and do the data validation and user object creation in the same
    script.
     
     
    >
    >
    >
    >I then used:
    >
    > set-user <username> -name "FirstName LastName"
    >
    >
    >
    >All fixed ;)
    >
    >
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Saturday, December 17, 2011 3:18 AM
  • Glad your problem has been resolved.

     

    Just as Rich said, you can use CSV file as a data source.

     

    Here are some commands you can used to create user with CSV files

     

    $users = import-csv  "C:\Users.csv"

    $container = [ADSI] "LDAP://cn=Users,dc=YourDomain,dc=local"

    $users | foreach {

        $UserName = $_.UserName

        $newUser = $container.Create("User", "cn=" + $UserName)

        $newUser.Put("sAMAccountName", $UserName)

        $newUser.SetInfo()

        $newUser.psbase.InvokeSet('AccountDisabled', $false)

        $newUser.SetInfo()

        $newUser.SetPassword("Password01!")

    }

     

    Thanks,

     

    Evan Liu

     

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support

    Monday, December 19, 2011 4:55 AM
    Moderator
  • Hi Mr.Kris,

     

    Now I will try to close the thread, If you still have any question on this issue, please feel free to let me know.

     

    Thanks,

     

    Evan Liu

     

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support

    Friday, December 23, 2011 2:27 AM
    Moderator
  • On Mon, 19 Dec 2011 04:55:30 +0000, Evan Liu wrote:
     
    >Here are some commands you can used to create user with CSV files
     
    The example suffers from the same problem -- it leaves
    leading/trailing whitespace where none should exist!
     
    This would take care of that situation:
    $UserName = $_.UserName.Trim()
     
    Vetting data before it's used is an important part of writing programs
    or scripts.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Monday, February 6, 2012 10:44 PM
  • Something like this might point out the problem:
     
    $u=get-user <USERNAME>
    $props = "firstname",
    "lastname",
    "displayname",
    "initials",
    "name",
    "samaccountname",
    "userprincipalname"
    $props | foreach{
    if ($u.$_.trim() -ne $u.$_)
    {
    write-host "Property $_ has leading or trailing spaces"
    }
    }
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP

    @Rich, maybe others are using it and not marking but +1 Very Helpful.  This helped me find which was messed up.  I combined that then with some quick commands and fixed 55+ of these issues in a snap.

    I used: 

    # Get users with leading or trailing spaces on Name or DisplayName
    $bad = Get-User -Filter { DisplayName -like '* ' -OR DisplayName -like ' *' -OR Name -like '* ' -OR Name -like ' *' }
    
    # Process list and fix leading and trailing spaces
    foreach( $a in $bad ) { Set-User $a.SamAccountName -DisplayName ($a.DisplayName.Trim()) -Name ($a.Name.Trim()) }
    
    # Get users with double spaces in Name or DisplayName
    $bad = Get-User -Filter { DisplayName -like '*  *' -OR Name -like '*  *' }
    
    # Process list replacing double spaces with single spaces
    foreach( $a in $bad ) { Set-User $a.SamAccountName -DisplayName ($a.DisplayName -replace '  ', ' ') -Name ($a.Name -replace '  ', ' ') }
    


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Tuesday, August 19, 2014 10:06 AM