Powershell Script to add AD users

I am new to systems admin and am taking a class. i am supposed to create a script that creates 100 new AD users. I’ve tried running it and I get an error “New-aduser : The name provided is not a properly formed account name” I tried soooo many different things. Please help me with any help possible. I’ve included a portion of what is actually a .csv file. and my script. Any help or tips will be greatly appreciated. Thank you.

First Name Initials Last Name Full Name User logon name password
aarona a curtis aarona curtis aarona.curtis Silverio0716
aaronb b curtis aaronb curtis aaronb.curtis Silverio0716

Import-Module active directory

$hundred = Import-csv c:\Users\Administrator.CURTISFAMINC\Documents\finalstep.csv

foreach ($user in $hundred)


$username = $user.username

$password = $user.password

$firstname = $user.fname

$lastname = $user.lname

new-aduser -samaccountname $username -name "$firstname $lastname" -givenname $firstname -surname $lastname -enabled $true -displayname "$lastname, $firstname" -scriptpath "C:\Users\Administrator.CURTISFAMINC\Documents\hundred" -accountpassword (convertto-securestring $password -asplaintext -force) 


Import-CSV expects the CSV to have values seperated by commas, not by spaces.

Also, the object variables you reference to (for example $user.username) are nowhere to be seen in your CSV file. How is powershell supposed to know what you want?

I would say you need to rename your headers in the CSV to the values your are using in your code or vice versa.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.