title: Error: "New-ADUser : The object name has bad syntax"
body: <p>I am creating a PowerShell script at work to copy user accounts.  The script works perfectly on my test Server 2016 VM. It also works in our work environment on a coworkers Windows 10 PC, however I cannot run it on my local machine.  It returns the following error:</p>
  
  <pre>
  New-ADUser : The object name has bad syntax
  At line:155 char:1
  + New-ADUser -Name $New_DisplayName @params
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (CN=cnelson test...ctions,DC=local:String) [New-ADUser], ADException
      + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser
  
  Add-ADGroupMember : Cannot find an object with identity: 'cnelsontest1' under:
  'DC=,DC=local'.
  At line:159 char:29
  + Add-ADGroupMember -Members $Username.Text
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (cnelsontest1:ADPrincipal) [Add-ADGroupMember], ADIdentityNotFoundException
      + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
  </pre>
  
  <pre><code>$params = @{'SamAccountName' = $Username.Text;
              'Instance' = $AD_Account_To_Copy;
              'DisplayName' = $New_DisplayName;
              'GivenName' = $FirstName.Text;
              'Path' = $New_Path;
              'SurName' = $LastName.Text;
              'ChangePasswordAtLogon' = $true;
              'Enabled' = $true;
              'UserPrincipalName' = $Username.Text;
              'AccountPassword' = $New_Pass;
              'EmailAddress' = $Username.Text + '@azcorrections.gov';
              'HomePage' = $HomePage.HomePage;
              'Description' = $NewDescription.Description;
              'Office' = $NewOffice.Office;
              'StreetAddress' = $NewStreet.StreetAddress;
              'City' = $NewCity.City;
              'State' = $NewState.State;
              'PostalCode' = $NewPostalCode.PostalCode;
              'Title' = $NewTitle.Title;
              'Department' = $NewDepartment.Department;
              'Company' = $NewCompany.Company;
              'ScriptPath' = $NewScript.ScriptPath;
              'OfficePhone' = $PhoneNumber.text;
              }
  
  New-ADUser -Name $New_DisplayName @params
  </code></pre>
  
  <p><a href="https://pastebin.com/ugJ6u9St" rel="nofollow noreferrer">Full Script link</a></p>
  
  <p>I'm running PSVersion 5.1.150</p>
  
  <p>Any ideas as to what i'm missing and why i'm coming across this error?  I have no idea what it is referring to, nor why it works on one coworkers computer but not my own.</p>
  
  <hr>
  
  <p><strong>Edit:</strong> Value of <code>$params</code> at the time of the error:</p>
  
  <pre>
  Name                  Value
  ----                  -----
  AccountPassword       System.Security.SecureString
  Description           Chris Nelson Test Account
  UserPrincipalName     cnelsontest1
  HomePage              http://...
  DisplayName           cnelson test1
  SamAccountName        cnelsontest1
  ScriptPath
  EmailAddress          cnelsontest1@example.com
  Office                test
  GivenName             cnelson
  Title                 SYSTEMS/LAN ADMR
  Company
  OfficePhone           555-1234
  StreetAddress         Sesame Street
  PostalCode            54321
  SurName               test1
  State                 candid
  Department            IT
  ChangePasswordAtLogon True
  Path                   cnelson,OU=IT_TECHSRVS,OU=Information Technology,OU=ADMIN,OU=CENT_OFF,DC=example,DC=com
  City                  
  Enabled               True
  Instance              CN=test\, cnelson,OU=IT_TECHSRVS,OU=Information Technology,OU=ADMIN,OU=CENT_OFF,DC=example,DC=com
  </pre>
  
  <p>I'm calculating <code>$New_Path</code> like this:</p>
  
  <pre><code>$New_Path = (Get-ADUser ($UsernameCopy.Text)).DistinguishedName -replace '^.*?,', ''
  </code></pre>