Solved

Active Directory bulk User import via .csv for Server2008 R2

Posted on 2010-09-15
13
4,281 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now