Bulk user creation is a big task and can be difficult to update manually all the required records/attributes in active directory if it is a business requirement.
Today we will learn, how to make this work in one shot with good accuracy
Today we will learn, how to make this work in one shot with good accuracy
Powershell:
There are many ways to make this work, but we will learn this through Powershell script and CSVDE command line.
Scenario 1:- Requirement to Create bulk users under Test OU with Description, Department, Manager, First/Last Name attributes updated and password set.
Create a Excel file with the required details as shown in the below figure and save it in CSV format.
Create a Excel file with the required details as shown in the below figure and save it in CSV format.
-Copy the below commands in notepad and save it as scipt.ps1 format. Both the files should be located in C drive.
$pass = "Password123"
$password = ConvertTo-SecureString "MyPassword123" -AsPlainText -Force $pass
Import-Csv "C:\testUsers.csv" | ForEach-Object {
$userPrincinpal = $_.samAccountName + @domain.com
New-ADUser -Name $_.Name -SamAccountName $_.samAccountName
-UserPrincipalName $userPrincinpal
-Path "OU=OUTest,DC=DOmain,DV=Com"
-Description $_.Description
-Manager $_.Manager
-givenname $_.FirstN
-surname $_.LastN
-ChangePasswordAtLogon $true
-Enabled $true
Add-ADGroupMember "Domain Admins" $_.samAccountName
}
Note:Import-Module Active directory and set-execution Policy unrestricted before you run the script.
The above command will help you to update the mentioned attributes; if the requirement is different in your scenario then you can find the exact attributes with the help of below cmdlets.
"Get-help New-ADUser –examples"
This will list out the string values with Examples.
Once you run the above command it will start creating user accounts and there you finish the task through powershell .
CSVDE:
Scenario 2:- We will create few users here with the help of CSVDE command.
CSVDE (Comma Separated Value Directory Exchange) is a command line utility, were we can export or import the user objects in Active directory.
Before we start with the activity, its best practice to go through with all the parameters/Syntax of CSVDE for your better understandings, when you use CSVDE –i -f sheet.csv to import the user account, ensure that LDAP fields mentioned in sheet are appropriate.
Here are the provided attributes in excel which describe as below,
- Objectclass – Defines the type of object
- GivenName – Defines First Name of user
- SN – Surname
- Description – Brief information about the object creation
- DN – Distinguished Name
- Save the file name in CVS format and run the below command
- Csvde –I –f c:\sheet.csv
s
-I used to import mode. If not specified, the default is export.
-f helps to import or export file name
After you run the command, you can easily see the results in Active Directory. If the results are not populating then please refresh the container and you will find the objects created.
Hope this information is helpful, please leave your comments below if any concerns and will get back to you.