title: New-Aduser : The object name has bad syntax
body: <p>I have a script which i use to create bulk users from a csv file which works fine. </p>
  
  <pre><code>Import-Csv e:\temp\newemps.csv | %{
      $ou = $_.ou
      $firstname = $_.first
      $lastName = $_.last
      $accountName = $("{0}{1}" -f $firstname.Substring(0,1),$lastName).ToLower()
      $description = $_.desc
      $password = "Welcome1"
      $name = "$firstName $lastName"
      New-AdUser -SamAccountName $accountName -GivenName $firstName -UserPrincipalName "$accountName@ba.net" -Surname $lastName -DisplayName $name  -Name $name -AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) -Enabled $true -Path $ou -Description $description -ChangePasswordAtLogon:$False
  
      If ($_.Group -ne ""){
          Add-adgroupmember -identity $_.group  -members $accountName
      }
  
      If ($_.email -eq "y"){
          Enable-Mailbox -Identity $accountName -Alias $accountName
          Set-Mailbox $accountName -MaxSendSize 10mb -MaxReceiveSize 10mb
          Get-CasMailbox $accountName -OwaEnabled:$false -ActiveSyncEnabled:$false
      }
  }
  </code></pre>
  
  <p>I was trying modify this script so that i could create some generic accounts that would not follow our typical convention. The input is a here-string as supposed to a csv as the only unique item is an Airport code. I have shortened the here-string for brevity.</p>
  
  <pre><code>$bases = @"
  YAB
  YEK
  YYH
  YHI
  "@
  
  $bases.Split("`n") | %{    
      $ou = "CN=Users,DC=BA,DC=NET"
      $firstname = "$_".ToString()
      $lastName = "Counter"
      $accountName =  "$_" + "Counter"
      $description = "Base Front Counter"
      $password = "Welcome1"
      $name = "$firstName $lastName"
      New-AdUser -SamAccountName $accountName -GivenName $firstName -UserPrincipalName "$accountName@ba.net" -Surname $lastName -DisplayName $name  -Name $name -AccountPassword (ConvertTo-SecureString -AsPlainText $password -Force) -Enabled $true -Path $ou -Description $description -ChangePasswordAtLogon:$False
  }
  </code></pre>
  
  <p>There is something about using a here-string that I am not accounting for. The only account it successfully creates is the one for <code>YHI</code> (The last one of the here-string). For all others it gives <code>New-AdUser : The object name has bad syntax</code>. Internet research shows many errors for csv-imports where the data has whitespace and other issues there but im not sure what the issue is here. </p>
  
  <p>In the end I just made a csv file instead of using the here-string but I would like to know what i was doing wrong. </p>