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" + "@mydomain.com"
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";
}
nav2567Asked:
Who is Participating?
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) {
$Person.Name
$Person.sn
$Person.Country
$Person.st
$Person.title
$Person.City
$Person.postalCode
$Person.telephoneNumber
$Person.Fax
$Person.givenName
$Person.displayName
$Person.department
$Person.company
$Person.SamAccountName
$Person.userPrincipalName
$Person.description
$Person.StreetAddress
$Person.Path
$Person.Password

New-ADUser -Name $Person.Name -Surname $Person.sn -Country $Person.Country -State $Person.st -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.

Will.
0
nav2567Author Commented:
What is your AD-Import.csv looked like?
0
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
etc...

Will.
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

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.
loginscript.png
0
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 $Person.sn

Once you have done that it will work for you.

Will.
0

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:
Thanks.
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.