PowerShell batch import/export Active Directory, powershellactive

Source: Internet
Author: User

PowerShell batch import/export Active Directory, powershellactive
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"123@abc" -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.


In windows 2003 server sp2, what are the batch commands used to export batch user names and import data to new servers?

I. Use CSVDE to export accounts
Using CSVDE to export the list of existing objects is quite simple.
The simplest usage is:
Csvde-f ad.csv directs the Active Directory object to the file named ad.csv. -F indicates the name of the output file.
However, you must note that the above usage is simple, but the exported results may have too many records and information you do not want.
To export records more accurately, you can use the-d,-r, and-l parameters.
Where:-d is used to specify a specific search location and range.
-R is used to specify a specific search object type.
-L is used to specify the specific attributes of the exported object.
For example:
Csvde-f users.csv-d "ou = Users, dc = contoso, dc = com"-r "(& (objectcategory = person) (objectclass = user)"-l DN, objectClass, description
Note: If the account information exported using CSVDE contains Chinese characters, garbled characters may exist. You can add the-U parameter to solve this problem.
Ii. Import accounts in batches
To import accounts in batches, a file containing multiple accounts must exist. Batch import is not allowed because there are no files.
Assume that you have used the csvdetool to export the users.csv file. The file content is as follows:

Name, full name, login name, password
Zhang, San, zhang San, three. zhang, pass01
Li, Si, li Si, four. li, passo2
Wang, Wu, wang Wu, five. wang, pass03
Liu, six. liu, passo4.
Zhao, Qi, zhao Qi, seven. zhao, pass05

With the above format, we can use the For command to read each piece of information in the file and use DSADD to add an account.
The statement is as follows:
C: \> for/f "tokens = 1, 2, 3, 4, 5 delims =," % a in (uses.csv) do dsadd user "cn = % c, ou =
Newusers, dc = contoso, dc = com "-samid % d-upn % d@contoso.com-fn
% B-ln % a-pwd % e-disabled no
Purpose: add the five accounts in the preceding file to the contoso.com domain named newusers OU, and the user is enabled by default.
Where-samid is the login name
-Upn is the logon name of UPN.
-Fn: Name
-Ln is the surname
-Pwd is the password

A brief explanation of the for statement
/F indicates reading information from the file
Tokens indicates the mark used by each row, which corresponds to the specific value of the Variable
Delims indicates the delimiter between each field... the remaining full text>
 
2003 batch export, Domain Users in use

Procedure:
I. Use CSVDE to export accounts
Using CSVDE to export the list of existing objects is quite simple.
The simplest usage is:
Csvde-f ad.csv directs the Active Directory object to the file named ad.csv. -F indicates the name of the output file.
However, you must note that the above usage is simple, but the exported results may have too many records and information you do not want.
To export records more accurately, you can use the-d,-r, and-l parameters.
Where:-d is used to specify a specific search location and range.
-R is used to specify a specific search object type.
-L is used to specify the specific attributes of the exported object.
For example:
Csvde-f users.csv-d "ou = Users, dc = contoso, dc = com"-r "(& (objectcategory = person) (objectclass = user)"-l DN, objectClass, description
Note: If the account information exported using CSVDE contains Chinese characters, garbled characters may exist. You can add the-U parameter to solve this problem.
Ii. Import accounts in batches
To import accounts in batches, a file containing multiple accounts must exist. Batch import is not allowed because there are no files.
Assume that you have used the csvdetool to export the users.csv file. The file content is as follows:

Name, full name, login name, password
Zhang, San, zhang San, three. zhang, pass01
Li, Si, li Si, four. li, passo2
Wang, Wu, wang Wu, five. wang, pass03
Liu, six. liu, passo4.
Zhao, Qi, zhao Qi, seven. zhao, pass05

With the above format, we can use the For command to read each piece of information in the file and use DSADD to add an account.
The statement is as follows:
C: \> for/f "tokens = 1, 2, 3, 4, 5 delims =," % a in (uses.csv) do dsadd user "cn = % c, ou =
Newusers, dc = contoso, dc = com "-samid % d-upn % d@contoso.com-fn
% B-ln % a-pwd % e-disabled no
Purpose: add the five accounts in the preceding file to the contoso.com domain named newusers OU, and the user is enabled by default.
Where-samid is the login name
-Upn is the logon name of UPN.
-Fn: Name
-Ln is the surname
-Pwd is the password

A brief explanation of the for statement
/F indicates reading information from the file
Tokens indicates the mark used by each row, which corresponds to the specific value of the Variable
Delims indicates the delimiter between each field... the remaining full text>
 

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.