New-ADUser to add bulk users with csv file

Posted on 2012-08-17
Last Modified: 2012-09-06
Import-Csv "c:\importausers.csv" | foreach-object {
$userprinicpalname = $_.SamAccountName + ""
New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $ -DisplayName $ -GivenName $_.GivenName -SurName $_.SurName -emailAddress $_.emailAddress -Description $_.Description -Path "OU=Users,DC=domain,,DC=com" -AccountPassword (ConvertTo-SecureString "Passw0rd" -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True}

CSV file headings are:

I keep getting error:
New-ADUser :directory object not found
at c:\createaduser.ps1:3 char:11
Question by:jazmanuni
    LVL 52

    Expert Comment

    by:Manpreet SIngh Khatra
    This command cannot be run from Exchange shell .... but Active Directory PowerShell


    - Rancy
    LVL 19

    Expert Comment

    Is that an exact copy and paste of your script?

    As you've made a typo in the 4th line down from the top - "$userprinicpalname" instead of "$userprincipalname"...
    LVL 19

    Expert Comment

    Oh don't worry, I can see the typo is also there where the variable is created so the fact that it's a typo won't make any difference! Ignore me! :)
    LVL 19

    Assisted Solution

    You might want to take a look at this:

    It's a simplified way of achieiving the same, based on the assumption that your csv column headers MUST be accurately spelt, and every attribute you want to specify (including path etc.) listed in the .csv.

    But the idea is that you could achieve the same thing simply be typing:

    Import-csv "c:\importausers.csv" | New-ADUser

    Looks a lot simpler to me than the method you're currently using...



    Accepted Solution

    Its being run from a DC Win 2008 R2, Powershell v2 (Not Exchange Powershell) with
    >Import-Module Active Directory

    Yes I see you dont have to define the variables in the script of they exist in the csv file.

    Its working now, I will show it here if it helps anyone else..

    CSV Headers for file c:\bulkaddadusers.csv


    1. Open powershell as administrator on DC
    2. >Import-Module Active Directory
    3. >Import-csv "c:\bulkaddadusers.csv | New-ADUser -AccountPassword (ConvertTo-SecureString -AsPlaintext "Pa$$w0rd" -Force | Enable-ADAccount

    All the enabled users will be created in the default OU = Users


    Author Closing Comment

    Exact method defined

    Featured Post

    Too many email signature changes to deal with?

    Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

    Join & Write a Comment

    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    OfficeMate Freezes on login or does not load after login credentials are input.
    This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
    The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now