[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4520
  • Last Modified:

Active Directory bulk User import via .csv for Server2008 R2

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
irishmic33
Asked:
irishmic33
1 Solution
 
Mike KlineCommented:
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
 
irishmic33Author 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

0
 
irishmic33Author 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
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
kadoroCommented:
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
 
irishmic33Author 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?
0
 
kadoroCommented:
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
 
kadoroCommented:
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
 
irishmic33Author 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

0
 
irishmic33Author 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
}
 
0
 
kadoroCommented:
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
 
irishmic33Author Commented:
I have not had time to test this solution.  Though skimming over it, I believe it should work correctly.
0
 
aparsons98Commented:
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now