Monday, August 26, 2013

Useful PowerShell Script to Bulk Create Users

Just used this script to generate 4000 users accounts within a development Active Directory.

 

The CSV has to be in the format:

 

##### CSV FILE ########

 

Name,Firstname,Password

User1,test,P@$$w0rd!1

User2,test,P@$$w0rd!1

User3,test,P@$$w0rd!1

User4,test,P@$$w0rd!1

############### START SCRIPT ################

 

Import-Module ActiveDirectory

$Users = Import-Csv -Delimiter ";" -Path ".\users.csv" 

foreach ($User in $Users) 

    $OU = "OU=Employees,DC=lab-os,DC=com" 

    $Password = $User.password

    $Detailedname = $User.firstname + " " + $User.name

    $UserFirstname = $User.Firstname

    $FirstLetterFirstname = $UserFirstname.substring(0,1)

    $SAM =  $FirstLetterFirstname + $User.name

    New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU 

}

 

############### END SCRIPT ################


Script credit goes to http://gallery.technet.microsoft.com/scriptcenter/ed20b349-9758-4c70-adc0-19c5acfcae45

 

 

No comments:

A little about Me

My photo
My name is Mitch Beaumont and I've been a technology professional since 1999. I began my career working as a desk-side support engineer for a medical devices company in a small town in the middle of England (Ashby De La Zouch). I then joined IBM Global Services where I began specialising in customer projects which were based on and around Citrix technologies. Following a couple of very enjoyable years with IBM I relocated to London to work as a system operations engineer for a large law firm where I responsible for the day to day operations and development of the firms global Citrix infrastructure. In 2006 I was offered a position in Sydney, Australia. Since then I've had the privilege of working for and with a number of companies in various technology roles including as a Solutions Architect and Technical team leader.