Create AD Accounts in Bulk with Powershell

in technology •  6 years ago 


Manual creation of Active Directory accounts is definitely a thing of the past and in this post i will show you how you can save hours of time with a simple csv file and a Powershell script.

Firstly you will need to compose a similar csv file to the one below and enter the specific details you need. Also pay close attention to the path section as this can easily cause issues. To find the Active Directory Path of the desired OU you can use the command below, this can then be pasted into the csv file.

Get-ADOrganizationalUnit -Filter ‘Name -like “ou name”‘ | select ‘distinguishedname’

CSV File

Once you have created the csv file and saved it to an easily accessible location, paste the below Powershell script into Powershell Ise (link in sources). This script will then take the details from the csv file and create User Accounts based on those details.

import-module activedirectory
Import-Csv "C:\path\users.csv" | ForEach-Object {
$userPrincipal = $."samAccountName" + "@yourdomain.com"
$password = ConvertTo-SecureString -AsPlainText $
."password" -force
New-ADUser -Name $_."user"
-Path $."path" -SamAccountName $_."samaccountname"
-DisplayName $
."Displayname" -Givenname $_."name"
-Surname $."surname" -UserPrincipalName $userPrincinpal
-AccountPassword $password -ChangePasswordAtLogon $true
-Enabled $true `
-Description $
."description"
}

The only thing you need to change from this script is the path to the csv file on line 2 and the domain name on line 3. Once it is ready you can run the script as administrator in Powershell Ise and then all the accounts will be created, Great Time Saver !

sources

https://docs.microsoft.com/en-us/powershell/scripting/getting-started/fundamental/windows-powershell-integrated-scripting-environment–ise-?view=powershell-6

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!