I am actually working on Automating User Creation. Initially, it picks up data from CSV and then it creates a user account in Active Directory, after creating user account it will enable mailbox for this user using the below command
Enable-mailbox -Identity usr1 Enable-mailbox -Identity usr1@domain.com
when I ran the command it throws the below error
I even tried removing the white space manually from the CSV before creating the user but still no luck. my question is which are the attributes that do not accept white space, as far as I know, CN does not accept space what else that do not accept white space and how I can solve this issue.
Basically, how I can trim or clear whitespace AD User Object before initiating Enable Mailbox
I tried the below command but no luck
# Get users with leading or trailing spaces on Name or DisplayName $bad = Get-User -Identity -usr1 { 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 -Identity -usr1 { 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 ' ', ' ') }