this is my code
Import-Csv C:\Users\Administrator\Desktop\ComputersUsers.csv |foreach {New-ADUser -GivenName $.GivenName -Surname $.Surname -DisplayName “$.DisplayName" -SamAccountName $.SamAccountName -UserPrincipalName $.UserPrincipalName -AccountPassword(ConvertTo-SecureString -AsPlainText “1234” -Force) -Enabled $true -ChangePasswordAtLogon $false -Name "$.DisplayName” -Path “$_.OU” }
this is my CSV
GivenName,Surname,DisplayName,SamAccountName,UserPrincipalName,accountpassword,OU
Namal,Computers1,Namal Computers 1,Computers1,Computers1@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers2,Namal Computers 2,Computers2,Computers2@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers3,Namal Computers 3,Computers3,Computers3@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers4,Namal Computers 4,Computers4,Computers4@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers5,Namal Computers 5,Computers5,Computers5@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers6,Namal Computers 6,Computers6,Computers6@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers7,Namal Computers 7,Computers7,Computers7@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers8,Namal Computers 8,Computers8,Computers8@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers9,Namal Computers 9,Computers9,Computers9@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers10,Namal Computers 10,Computers10,Computers10@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers11,Namal Computers 11,Computers11,Computers11@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers12,Namal Computers 12,Computers12,Computers12@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers13,Namal Computers 13,Computers13,Computers13@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers14,Namal Computers 14,Computers14,Computers14@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers15,Namal Computers 15,Computers15,Computers15@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Namal,Computers16,Namal Computers 16,Computers16,Computers16@students.local,1234,“”“OU=ComputersRoom,OU=Namal,OU=Users,OU=StudentsLocal,DC=students,DC=local”“”
Why is not working correctly?
ERROR:
New-ADUser : The object name has bad syntax
At C:\PowershellScript\New-Aduser from csc.ps1:2 char:72
- Import-Csv C:\Users\Administrator\Desktop\ComputersUsers.csv |foreach {New-ADUse …
-
+ CategoryInfo : NotSpecified: (CN=@{GivenName\...s,DC=local"}.OU:String) [New-ADUser], ADException + FullyQualifiedErrorId : The object name has bad syntax,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Thank you for your help
Itamar.