+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, PowerShell Bulk create Users from csv in Coding and Web Development; Hello all, Thought I would share this as it has taken 2 hours of mashing my head against a wall ...
  1. #1

    Join Date
    Jun 2007
    Thank Post
    Thanked 35 Times in 30 Posts
    Rep Power

    PowerShell Bulk create Users from csv

    Hello all,

    Thought I would share this as it has taken 2 hours of mashing my head against a wall getting it working and thought I would spare others a bit of pain

    This script uses the 'Active Directory module for Windows Powershell' but the key point (that took me ages to work out, and seems mad) is you should not run it from a domain controller! instead I ran it from a member server while logged in as a Domain Admin

    Import-Csv .\2012Users.csv | foreach-object {
    $userprinicpalname = $_.SamAccountName + "@yourdomain.com"
    New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprinicpalname -Name $_.name -DisplayName $_.name -GivenName $_.FirstName -SurName $_.LastName -Path "OU=year7,OU=Pupils,DC=yourdomain,DC=com" -AccountPassword (ConvertTo-SecureString "Passwordgoeshere" -AsPlainText -force) -Enabled $True -ChangePasswordAtLogon $True -PassThru }
    obviously change the yourdomain.com, path to the OU and default password to suit your school.

    the CSV should have the following columns


    when run the script will create the users, using their login name as the Display name. No Profile or home folder will be set - this could be added in I think, but is straight forward enough to do in AD users and computers (and I was fed up with tinkering in powershell by that point!)

    Hope this is useful to someone.

  2. 3 Thanks to Chris_Jones:

    mac_shinobi (9th August 2012), sidewinder (23rd August 2012), stevenlong1985 (27th September 2012)

  3. #2

    Join Date
    Feb 2014
    Thank Post
    Thanked 0 Times in 0 Posts
    Rep Power


    I know I'm a little late to the game here sorry, however I have updated this a little bit to be more flexible, if not readable.

    $import = Import-Csv .\Users.csv
      foreach-object -input$import {
          $upn = $_.SamAccountName +"@YOURDOMAIN"
          $name = $_.name
          $displayname = $_.name
          $givenname = $_.FirstName
          $surname = $_.Lastname
          $Password = "PASSWORD GOES HERE"
          $enabled = $True
          $changePW = $False
          new-ADUser -Name$name -SamAccountName $_.SamAccountName -UserPrincipalName $upn -DisplayName $displayname -GivenName $givenname -SurName $surname -Path $path -AccountPassword (ConvertTo-SecureString $password -AsPlainText -force) -Enabled $enabled -ChangePasswordAtLogon $changePW -PassThru
    Last edited by neil1775; 10th February 2014 at 06:54 PM.

+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 26th July 2011, 11:10 AM
  2. Replies: 0
    Last Post: 28th January 2011, 03:38 PM
  3. Tool to bulk create users / create single user easily?
    By reggiep in forum Windows Server 2008
    Replies: 9
    Last Post: 27th May 2010, 12:30 PM
  4. Create bulk ad groups from a csv file
    By ful56_uk in forum Windows
    Replies: 2
    Last Post: 20th July 2009, 05:06 PM
  5. Bulk Remove Users from OU?
    By indiegirl in forum How do you do....it?
    Replies: 11
    Last Post: 17th August 2006, 03:23 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts