Powershell batch import/export Active Directory recently, due to company requirements, 20 suppliers and 20 customers need to be imported to the ad domain. At first, two suppliers and two customers have been manually added. However, it is time-consuming and labor-intensive. If you can find a command, how nice it is to import ad in batches. Because a senior engineer left a document on AD and found that the commands exported by users in the ad domain are as follows:
csvde -f E:\20131015.csv -r "(objectClass=user)" -d "OU=XXX,DC=XXX,DC=com" -u
Ou is processed here. You should replace it with your own attribute value when using it. This command exports the ad user to the E disk. I use the current date as the file name and save it as a CSV file (the CSV file can be opened in Excel ).
Next we will discuss how to import ad users in batches. The same as above, we use CSV files to import user data to the organizational unit of AD. Enter csvde /? (Note the space in the middle) Check what commands are available.
After knowing the csvde command, let's start importing data step by step. Enter related information in Excel and save it as a CSV file.
Put the file on the drive with the name adinfor.csv. Run powershell as the administrator and enter the following command:
Import-Csv f:\ADInfor.csv | foreach {New-ADUser -Name $_.name -SamAccountName $_.samaccountname -UserPrincipalName $_.userprincipalname -GivenName $_.givenname -Surname $_.surname -DisplayName $_.displayname -Path $_.path -AccountPassword(ConvertTo-SecureString"[email protected]" -AsPlainText -Force) -ChangePasswordAtLogon $true -Enabled $true}
I encountered a prompt error-the New-aduser item cannot be recognized as the name of the cmdlet, function, script file, or runable program.
So I entered the get-command in powershell to check which commands are available... No ad-related commands were found. No new-aduser is found.
Close powershell, right-click powershell again, and choose import system module. After the import is complete, enter the get-command. We can see that new-aduser is already in the Command Group.