Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Adding Bulk Users in AD

Posted on 2012-08-11
14
Medium Priority
?
960 Views
1 Endorsement
Last Modified: 2012-08-14
I am trying to find a good way to add bulk users in AD.  I know it can be scripted in powershell but I havent had much luck with that.

I just want to add users, drop them in an OU, set the password and force them to change it at login.

What is the best way to do this, Powershell?  If so, how do you do it in powershell?
This is a Windows 2k8 domain, domain fucntional level at 2k3.

TIA
1
Comment
Question by:Earl28
  • 3
  • 3
  • 2
  • +6
14 Comments
 
LVL 13

Expert Comment

by:p_nuts
ID: 38284412
0
 
LVL 13

Expert Comment

by:p_nuts
ID: 38284447
What format do you have the users details in?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Earl28
ID: 38284459
CSV, and its just FirstName,LastName.
0
 

Author Comment

by:Earl28
ID: 38284462
Here is what I have, I ripped it off some site, so I didnt write it.  (disclaimer)

$objOU=[ADSI]"LDAP://OU=NewUserDump,OU=CCA Campus,DC=mydomain,DC=local"
$dataSource=import-csv "adduser.csv"
foreach($dataRecord in $datasource) {
$cn=$dataRecord.FirstName + " " + $dataRecord.Lastname
$SAMAccountName=$dataRecord.FirstName + "." + $datarecord.LastName
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$SAMAccountName=$SAMAccountName.ToLower()
$displayName=$sn + ", " + $givenName
$userPrincipalName=$SAMAccountName + "@mydomain.local"

$objUser=$objOU.Create("user", "CN="+$cn)
$objUser.Put("SAMAccountName",$SAMAccountName)
$objUser.Put("userPrinciplaName",$userPrincipalName)
$objUser.Put("dispalyname",$displayName)
$objUser.Put("givenName",$givenName)
$objUser.Put("sn",$sn)

$objUser.SetInfo()
$objUser.SetPassword("password")
$objUser.psbase.InvokeSet("AccountDisabled",$false)
$objUser.SetInfo()
}


When I run it in powershell, it doesnt like the last 4 lines, in regard to the password.  I removed those lines, the script ran without error, but no user account was created in the specified OU.

I am running the script as Admin in Powershell and have changed the ExecutionPolicy.
0
 
LVL 8

Assisted Solution

by:Brent Challis
Brent Challis earned 400 total points
ID: 38284478
Here is a script that I have written to create a collection of users based on a csv file.  I am reading more information that you have mentioned form the file so you can prune the code down.  I am using the Department entry in the csv file to both populate the Department property and to put them in an OU of the same name.  This requires the ActiveDirectory web service to be present on the DC.

The headers for the columns of my csv file are:
EmployeeID      Surname      GivenName      Initial      Title      Suffix      JobTitle      Department      Division      EmailAddress      PhoneNumber      SAMAccount      City      PostalCode      StateProvince      CountryRegionCode      Country      UPN
CreateUpdateUserAccounts.txt
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38284680
You can also use CSVDE -I switch.
This will create users from a standard csv file.   It is part of windows.
http://technet.microsoft.com/en-us/library/cc732101(v=ws.10).aspx
I find it is a bit more straight forward, but learning PS is not a bad way to import and learn scripting.
0
 
LVL 19

Expert Comment

by:*** Hopeleonie ***
ID: 38284878
We created with CSV, but I think you can choose a format.
0
 
LVL 13

Expert Comment

by:p_nuts
ID: 38284907
You haven't referenced the ou in the create function. You only fill a variable with the ou info..

also its much easier you use the built in function..

new-ADUser

http://technet.microsoft.com/en-us/library/ee617253.aspx
0
 
LVL 70

Expert Comment

by:KCTS
ID: 38285083
There are lots of free tools available - why re-invent the wheal

eg http://ad-bulk-users.software.informer.com/
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38285719
Creating bulk Active Directory user and group accounts in PowerShell using Server 2008 R2 cmdlet
http://get-spscripts.com/2011/08/creating-bulk-active-directory-user-and.html

Sub-Topics
To create my users in the OU “*****” for the domain “****.local”
Creating groups and assigning members

- Rancy
0
 
LVL 58

Expert Comment

by:McKnife
ID: 38288938
You can also use batch.
Fire the command dsadd user /? and see what's possible. Try using a for loop on your .csv/textfile.
0
 
LVL 2

Accepted Solution

by:
Sergey Kolesnik earned 1600 total points
ID: 38289564
0
 

Author Closing Comment

by:Earl28
ID: 38290419
Thanks for all the input.  I ended up using the ANUC tool that dreik mentioned.  It was good, the CSV part was a bit flaky, so I added them manually using the tool.  It took me 2 hours to add 500 users, so not bad.<br /><br />it doesnt allow you to add group membership, if it had that it would be great.<br /><br />Thanks again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question