Active Directory, General, Microsoft Windows Server 2012

Create Active Directory Users using csv file

This script allows to create Active Directory users using a CSV file and set specific password, email address, and add users to one group for each user.

import-module activedirectory
Import-Csv "C:\Users\admin\Desktop\file.csv" | ForEach-Object {
$userPrincinpal = $_."samAccountName" + "@company.Local"
New-ADUser `
-Name $_."user" `
-Givenname $_."name" `
-Surname $_."surname" `
-SamAccountName  $_."samaccountname" `
-Path  $_."path" `
-DisplayName $_."dispalyname" `
-UserPrincipalName  $userPrincinpal `
-AccountPassword (ConvertTo-SecureString $_."Password" -AsPlainText -Force) `
-ChangePasswordAtLogon $true  `
-Enabled $true `
-EmailAddress ($_."samaccountname"+"@company.local") `
-Description $_."description" 
 Add-ADGroupMember -Identity $_."group" -Members $_."samaccountname";

Remember to change csv path and userprincipal.
To add different mail address, add a column on csv file called “mail” and set username@mailaddress, then set on line 24 -EmailAddress $._”mail”.

CSV file Example