Solved

Active Directory bulk User import via .csv for Server2008 R2

Posted on 2010-09-15
13
4,372 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)

http://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.
0
Comment
Question by:irishmic33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 57

Expert Comment

by:Mike Kline
ID: 33685603
Take a look at the powershell section and look at some of Chris Dent's answers, example   http://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
0
 
LVL 2

Author Comment

by:irishmic33
ID: 33691177
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

0
 
LVL 2

Author Comment

by:irishmic33
ID: 33692608
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
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Expert Comment

by:kadoro
ID: 33692621
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)
0
 
LVL 2

Author Comment

by:irishmic33
ID: 33692970
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?
0
 
LVL 1

Expert Comment

by:kadoro
ID: 33693049
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!
0
 
LVL 1

Expert Comment

by:kadoro
ID: 33693061
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

0
 
LVL 2

Author Comment

by:irishmic33
ID: 33693971
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

0
 
LVL 2

Author Comment

by:irishmic33
ID: 33693983
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
}
 
0
 
LVL 1

Accepted Solution

by:
kadoro earned 500 total points
ID: 33694708
Spent a few more minutes on this sorry I was distracted.

This code should work to provision.  I split the Import-csv to a separate line because it makes it easier to segment what is being done.

Also included the test file. users.csv.  Make sure you are using the ISE Powershell V2 interface and step through each line to ensure you know what you are getting.

You should be fine from here.    Don't forget to reload the -UserPassword option in new-qaduser (and to the CSV)  I didn't put that in my last code revision.




$OuDomain = "OU=Test OU,DC=my,DC=com"
$Csv = "c:\go\users.csv"
 
# Update details. Add/remove depending on which details to update.
$list =import-csv $Csv 
$list|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

users.csv
0
 
LVL 2

Author Closing Comment

by:irishmic33
ID: 33839744
I have not had time to test this solution.  Though skimming over it, I believe it should work correctly.
0
 

Expert Comment

by:aparsons98
ID: 34451456
I use a program for this -

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

It works great might be worth chking it out.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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