PowerShell imports AD domain users in bulk
For Windows server operation and maintenance staff, learning Powershell can greatly reduce their workload and improve efficiency.
Here is a problem I encountered in my work. There are 50 interns in the company, so I need to create an AD account for these 50 users. It is conceivable that it is a waste of time and time to operate one by one through the graphical interface.
Energetically, then when you learn to use Powershell, you can enter the information of these 50 people into the excel table, and then import it at one time using Powershell. Isn't it convenient to share the commands below?
Command: Import-Csv 'C:\ New\ AddADUser.csv' | ForEach-Object {New-ADUser-SamAccountName $. SamAccountName-Surname $. Surname-GivenName $. GivenName-Name $. Name-UserPrincipalName $. UserPrincipalName-DisplayName $. DisplayName-Description $. Description-Path $. Path-AccountPassword (ConvertTo-SecureString-AsPlainText $_. AccountPassword-Force)-Enabled 1-ChangePasswordAtLogon 1}
CSV template layout:
Note: CSV should be saved in UTF-8, otherwise Chinese will be garbled. You should be clear about the parameters corresponding to the template and don't fill in the template incorrectly. Enable 1, the number 1 indicates that the account is enabled, ChangePasswordAtLogon 1, and the number 1 indicates that the password needs to be changed the next time you log in. If the number is changed to 0, the account is disabled, and the next login does not need to change the password.
Import the effect drawing:
The tests are all in the virtual machine environment, no problem is running in the production environment.