Bulk User Account Creation using PowerShell
Provisioning users in Active Directory usually means onboarding the users across Exchange, Microsoft 365 and other systems. However, onboarding multiple users at once can quickly turn out to be a laborious task, with administrators having to repeat the same steps again and again. This also means that administrators can make errors while provisioning users that might prove detrimental to the security of the Windows environment. However, user accounts can be provisioned in bulk more easily with the help of PowerShell script.
Creating bulk users in Active Directory using PowerShell
- Import-Module ActiveDirectory
- $file = "\\SERVER\csv\users.csv"
- $importedUsers = Import-csv $file
- foreach ($user in $importedUsers)
- {
- $sAMAccountName = $user.sAMAccountName
- $password = ConvertTo-SecureString -AsPlainText $user.password -Force
- $givenName = $user.givenName
- $sn = $user.sn
- $ou = $user.ou
- $name = $givenName+"."+$sn
- New-ADUser -SamAccountName $sAMAccountName -Name $givenName
- -AccountPassword $password -GivenName $givenName -Surname $sn
- -Enabled $True -path $ou
- }
By default, when the accounts are created, the users are required to change the default passwords at the next logon. To simplify bulk user creation even further, the script can be scheduled to run periodically.