Create multiple user accounts using Powershell

I am running the below PS script to read this NEWUSERS.CSV file:

Name            samaccountname            ParentOU
testuser1      testuser1            ou=testou,dc=mydomain,dc=com
testuser2      testuser2            ou=testou,dc=mydomain,dc=com

but I do not see any users being created.  I do not see any error when I run the script.  

Please advise.  Thanks.

Import-Module ActiveDirectory
Import-Csv "C:\bin\script\addadusers\NewUsers.csv" | ForEach-Object {
 $userPrincinpal = $_."samAccountName" + ""
New-ADUser -Name $_.Name `
 -Path $_."ParentOU" `
 -SamAccountName  $_."samAccountName" `
 -UserPrincipalName  $userPrincinpal `
 -AccountPassword (ConvertTo-SecureString "Mypwd$12" -AsPlainText -Force) `
 -ChangePasswordAtLogon $true  `
 -Enabled $true
Add-ADGroupMember "Domain Admins" $_."samAccountName";
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
The script below is one that i created that i use all of the time for multiple accounts give that a shot.
Import-module activedirectory

Userlist = Import-Csv "C:\AD-Import.csv"

ForEach ($Person in $Userlist) {

New-ADUser -Name $Person.Name -Surname $ -Country $Person.Country -State $ -Title $Person.title -City $Person.City -PostalCode $Person.postalCode -OfficePhone $Person.telephoneNumber -Fax $Person.Fax -GivenName $Person.givenName -DisplayName $Person.displayName -Department $Person.department -Company $Person.Company -SamAccountName $Person.SamAccountName -UserPrincipalName $Person.userPrincipalName -Description $Person.description -StreetAddress $Person.StreetAddress -Path $Person.Path -Enabled $true -AccountPassword (ConvertTo-SecureString $Person.Password -AsPlainText -force)

Open in new window

You will need to construct your csv headings with the same as i have Outlined in the script. If you do not want all of the settings just remove the ones that do not apply.

nav2567Author Commented:
What is your AD-Import.csv looked like?
Will SzymkowskiSenior Solution ArchitectCommented:
Where ever you see $Person.something I have a column heading for this. Below would be each users details.

Example below...

Name   sn           country    state       title .....
Mike          Smith     Canada    Ontario   Accountant

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

nav2567Author Commented:
Thanks. I need to specify the name of the login script in the user's properties.  

I added the scriptpath column but it does not work.

Can you advise again?  Please see screenshot.
Will SzymkowskiSenior Solution ArchitectCommented:
All you need to do is add a column heading called script (or whatever you want).

Then add $Person.Script on its own line where you see the rest of the headings.

Then add to on line 26 -ScriptPath $Person.Script.

You can add this after the -Surname $

Once you have done that it will work for you.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nav2567Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.