Powershell batch import/export Active Directory

Source: Internet
Author: User
Tags samaccountname
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.