none
New-ADUser : The object name has bad syntax RRS feed

  • Question

  • I've spent all day on this.  Worse yet, I have done this many times before at my last job.  

    I am trying to create users from a csv file but keep getting "New-ADUser : The object name has bad syntax"

    Here is my latest failed script:

    Import-Csv "c:\scripts\basic user import\studentTest3.csv" | ForEach {
    
        New-ADUser -Name "$($_.FirstName) $($_.LastName)" -DisplayName "$($_.FirstName) $($_.Lastname)" -SamAccountName $_.StudentUsername -UserPrincipalName "$($_.Firstname).$($_.Lastname)@$($_.Maildomain)" -GivenName $_.Firstname -Surname $_.Lastname -Description $_.Description -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) -Enabled $true -Path $_.OU -ChangePasswordAtLogon $false –PasswordNeverExpires $true
    
    }
    }

    My CSV:

    LastName,FirstName,Maildomain,StudentUsername,OU,Password,Description
    John,Smith,domain.org,jsmith27,"OU=Users,OU=test,DC=sub,DC=domain,DC-ORG",aa205120,Class of 2027

    Monday, July 25, 2016 6:08 PM

Answers

  • Sorry for wasting your time.  I had DC-ORG instead of DC=ORG.  I am ashamed of myself.  I wish I can remove this post so I never remind myself of this moment...
    • Marked as answer by strensnick Monday, July 25, 2016 6:48 PM
    Monday, July 25, 2016 6:48 PM

All replies

  • Fix the dash on -PasswordNeverExpires. Looks to be em/en.

    Monday, July 25, 2016 6:12 PM
  • Start by posting the complete error.


    \_(ツ)_/

    Monday, July 25, 2016 6:12 PM
  • Import-Csv "c:\scripts\basic user import\studentTest3.csv" | 
    	ForEach {
    		$userprops=@{
    			Name ="$($_.FirstName) $($_.LastName)" 
    			DisplayName= "$($_.FirstName) $($_.Lastname)" 
    			SamAccountName =$_.StudentUsername 
    			UserPrincipalName= "$($_.Firstname).$($_.Lastname)@$($_.Maildomain)" 
    			GivenName= $_.Firstname 
    			Surname= $_.Lastname 
    			Description= $_.Description 
    			AccountPassword= (ConvertTo-SecureString $_.Password -AsPlainText -Force) 
    			Enabled= $true 
    			Path= $_.OU 
    			ChangePasswordAtLogon= $false 
    			PasswordNeverExpires= $true
    		}
    		New-AdUser @userprops
    	}
    


    \_(ツ)_/

    Monday, July 25, 2016 6:18 PM
  • here is the complete error:

    New-ADUser : The object name has bad syntax
    At C:\scripts\basic user import\Create-BulkADUsersMLB-studentTest3.ps1:3 char:5
    +     New-ADUser -Name "$($_.FirstName) $($_.LastName)" -DisplayName "$ ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=John Smith,O...ESCHOOLS,DC-ORG:String) [New-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser

    Monday, July 25, 2016 6:21 PM
  • yes, that was an incorrect dash but it did not fix the error.
    Monday, July 25, 2016 6:21 PM
  • Either the name already exists or you have a bod OU designation or your AD is corrupt.  Look for users with same name or remove OU and test.

    \_(ツ)_/

    Monday, July 25, 2016 6:25 PM
  • This is a brand new AD environment. I am the only user.  I tried your script above and changed the OU paths and I keep getting the same error.  I thought I found the problem when I noticed the Maildomain in my csv file should have been sub.domain.org.  I changed that but it still gets the same error.

    Monday, July 25, 2016 6:42 PM
  • Sorry for wasting your time.  I had DC-ORG instead of DC=ORG.  I am ashamed of myself.  I wish I can remove this post so I never remind myself of this moment...
    • Marked as answer by strensnick Monday, July 25, 2016 6:48 PM
    Monday, July 25, 2016 6:48 PM
  • Remove things one at a time until you find the issue.  It is hard for us to see all of the data and deduce where all of your typos are.  Typos are the first thing that is very hard to find with plain text posts.


    \_(ツ)_/

    Monday, July 25, 2016 7:08 PM