Powershell script to bulk import users into Active Directory

If you need to import users in bulk into Active Directory, the following script will do this:-

NOTE:- You will need to change @Domainname to your actual domain name, I just called it this in the script for test purposes.

#NOTE:-Powershell Execution Policy to needs to be set as unrestricted
#The Name field correlates to the FullName of the user i.d. attribute in ADUC
#The DisplayName property correlates to the Displayname attribute in ADUC
#The Givenname property correlates to the First Name attribute in ADUC
Import-Module ActiveDirectory
Import-Csv “C:\Users.csv” | ForEach-Object {
$userPrincipal = $_.”samAccountName” + “@Domainname.com”
New-ADUser -Name $_.Name `
-Path $_.”ParentOU” `
-SamAccountName  $_.”samAccountName” `
-UserPrincipalName  $userPrincipal `
-Displayname $_.”Displayname” `
-Givenname $_.”Firstname” `
-Surname $_.”Surname” `
-AccountPassword (ConvertTo-SecureString -AsPlainText $_.password -Force) `
-PasswordNeverExpires $True `
-ChangePasswordAtLogon $false  `
-Enabled $true

The script will read a csv file that needs to be created in the following format, obviously you need to replace the information underneath the headers with the information that is relevant for your domain.




This entry was posted in Non SCOM Techy Stuff and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s