Create Bulk Users in Active Directory using PowerShell

Create Bulk Users in Active Directory using PowerShell

There are multiple ways to create bulk users in Active Directory like – Manually using Active Directory Users and Computers MMC snap-in, VB Script, tools like LDIF or PowerShell.  Using PowerShell in most easy and let us see how

Create an Organizational Unit using PowerShell :

New-ADOrganizationalUnit -Name "IT" -Path "DC=Contoso,DC=Com"

Create-Bulk-Users-AD_1

Create list of users in CSV format:

Fields that are required for User Creation are:

First Name, Last Name, UPN, SAM Account Name, Password and Organizational Unit Path

Create a CSV file that looks like this: Create-Bulk-Users-AD_2

Now, we need to use New-ADUser command to create new users from the CSV file. However, the command doesn’t accept Account password in clear text,  so we have to use Read-Host command for supplying password to the command.

$MyPassword = Read-Host "Enter Password " -AsSecureString

Import-CSV <Path of CSV-File> | foreach {New-ADUser -Path $_.path -GivenName $_.firstname -Surname $_.lastname -DisplayName $_.displayname -Name $_.displayname -UserPrincipalName $_.upn -SamAccountName $_.sam -Enabled:$True -AccountPassword $MyPassword}

Notice that fields from the CSV are called with “$_.” prefix and PowerShell variable (MyPassword) are called with “$” prefix.

Create-Bulk-Users-AD_3

The command has created users listed in the CSV file successfully.

Create-Bulk-Users-AD_4

 

About The Author

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *