Solved

Active Directory bulk User import via .csv for Server2008 R2

Posted on 2010-09-15
13
4,331 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
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…

831 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