We help IT Professionals succeed at work.

Active Directory bulk User import via .csv for Server2008 R2

4,770 Views
Last Modified: 2012-05-10
2008 R2 Active Directory mass import has me stumped.

I've spent the day searching and researching and I'm still unclear on exactly how to easily mass import users into AD via a .csv file.  The following link is about the best walkthrough I've found, but unfortunatley my powerscript chokes on the import-csv command in powershell. (which then sent me on another wild goosechase)

https://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_25113109.html?sfQueryTermInfo=1+10+2008+30+csv+import+password+set+us+user

The .csv file will at a minimum contain the data of:

- firstname
- lastname
- username
- password

I beleive a powershell script is probably the best method as I'm working with 2008 for the first time.  A walkthrough would be great, but I'm willing to drudge through the mud if needed cause I need to learn the process for the future.  

I previously had a 2003 script working from Joe called ADmod, but the link appears to be down and I seem to have lost the files in my server upgrades.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2013

Commented:
Take a look at the powershell section and look at some of Chris Dent's answers, example   https://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_24736308.html
For a lot of the answers you will need the quest ad cmdlets.  I'll also add the powershell zone
You can still get admod from joe's site too.
Thanks
Mike

Author

Commented:
mkline71:  
Ok, I'm following that example and it appears to be really simple...  Thanks for the quick reply.

Does anyone know how to add the password variable to this import?  

These will be student accounts and they will have specific password assigned to each user.  I will be able to provide the specific password via the .csv file.




$OuDomain = "OU=Imports,DC=my,DC=com"
$Csv = "c:\users.csv"
 
# Update details. Add/remove depending on which details to update.
import-csv $Csv | ForEach-Object {
  New-QADUser 
    -ParentContainer $OuDomain `
    -Name $_.name `
    -SAMAccountName $_.sAMAccountName `
    -Description $_.description `
    -GivenName $_.givenName `
    -SN $_.SN `
    -DisplayName $_.displayName `
    -ObjectAttributes @{ profilePath="$($_.ProfilePath)" }
  Enable-QADUser $_.name 
}

Open in new window

Author

Commented:
I've actually created more issues by changing the code I think.   Or maybe I have other issues.  Here is the error I am receiving in powershell when I run it.

Here is the code:

$OuDomain = "OU=Imports,DC=my,DC=com"
$Csv = "c:\users.csv"
 
# Update details. Add/remove depending on which details to update.
import-csv $Csv | ForEach-Object {
  New-QADUser
    -ParentContainer $OuDomain `
    -Name $_.name `
    -SAMAccountName $_.sAMAccountName `
    -Description $_.description `
    -GivenName $_.givenName `
    -SN $_.SN `
    -DisplayName $_.displayName `
  Enable-QADUser $_.name
}
 

Here is the error:
PS C:\> .\adusersscript.ps1
Missing expression after unary operator '-'.
At C:\ADusersScript.ps1:7 char:6
+     - <<<< ParentContainer $OuDomain `
    + CategoryInfo          : ParserError: (-:String) [], Pars
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

Commented:
To add the password you just need to use the -UserPassword option in the new-qadUser command.
If you add it to your CSV that is imported you would just reference it through $_.password (assuming that is your format)

Author

Commented:
Thanks kadoro I just didn't know the exact verbiage to use.  I'll add that to the code.

Any idea on the error from above?

Commented:
Error above relates the additional return added after the NEW-QADUSER command.  If your command span multiple lines you must include the " ' " (single quote) like the other lines show.

Good luck!

Commented:
See the slight differnece in formatting?
# Update details. Add/remove depending on which details to update.
import-csv $Csv | ForEach-Object {
  New-QADUser -ParentContainer $OuDomain `
    -Name $_.name `
    -SAMAccountName $_.sAMAccountName `
    -Description $_.description `
    -GivenName $_.givenName `
    -SN $_.SN `
    -DisplayName $_.displayName `
    -ObjectAttributes @{ profilePath="$($_.ProfilePath)" }
  Enable-QADUser $_.name 
}

Open in new window

Author

Commented:
Understood, I see where the changes were needed, but the error seems to still remail.  

Error:
-------------------------
PS C:\> .\adusersscript.ps1
The term 'New-QADUser' is not recognized as the name of
 spelling of the name, or if a path was included, verify
At C:\ADusersScript.ps1:6 char:14
+   New-QADUser <<<<  -ParentContainer $OuDomain `
    + CategoryInfo          : ObjectNotFound: (New-QADUs
    + FullyQualifiedErrorId : CommandNotFoundException

-----------------------------------------------------------------

Any ideas?
# Update details. Add/remove depending on which details to update.
import-csv $Csv | ForEach-Object {
  New-QADUser -ParentContainer $OuDomain `
    -Name $_.name `
    -SAMAccountName $_.sAMAccountName `
    -Description $_.description `
    -GivenName $_.givenName `
    -SN $_.SN `
    -DisplayName $_.displayName `
    -UserPassword $_.userpassword `
  Enable-QADUser $_.name 
}

Open in new window

Author

Commented:
Code snipet was only the lower portion.   This is full code.

-----------------------

$OuDomain = "OU=Imports,DC=my,DC=com"
$Csv = "c:\users.csv"
 
# Update details. Add/remove depending on which details to update.
import-csv $Csv | ForEach-Object {
  New-QADUser -ParentContainer $OuDomain `
    -Name $_.name `
    -SAMAccountName $_.sAMAccountName `
    -Description $_.description `
    -GivenName $_.givenName `
    -SN $_.SN `
    -DisplayName $_.displayName `
    -UserPassword $_.userpassword `
  Enable-QADUser $_.name
}
 
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I have not had time to test this solution.  Though skimming over it, I believe it should work correctly.
I use a program for this -

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx

It works great might be worth chking it out.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.