Link to home
Start Free TrialLog in
Avatar of Earl28
Earl28Flag for United States of America

asked on

Adding Bulk Users in AD

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
Avatar of p_nuts
p_nuts
Flag of Netherlands image

What format do you have the users details in?
Avatar of Earl28

ASKER

CSV, and its just FirstName,LastName.
Avatar of Earl28

ASKER

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.
SOLUTION
Avatar of Brent Challis
Brent Challis
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
We created with CSV, but I think you can choose a format.
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
There are lots of free tools available - why re-invent the wheal

eg http://ad-bulk-users.software.informer.com/
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
You can also use batch.
Fire the command dsadd user /? and see what's possible. Try using a for loop on your .csv/textfile.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Earl28

ASKER

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.