Link to home
Start Free TrialLog in
Avatar of nav2567
nav2567Flag for United States of America

asked on

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";
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

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.

Avatar of nav2567


What is your AD-Import.csv looked like?
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

Avatar of nav2567


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.
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nav2567