PowerShell Bulk Add Domain Users (Windows R2)

Source: Internet
Author: User

PowerShell version


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7B/16/wKioL1bGxGiB8yiRAAA-9Ru1OwY846.png "title=" PowerShell version. png "alt=" Wkiol1bgxgib8yiraaa-9ru1owy846.png "/>

1. Prerequisites for Implementation please prepare the relevant domain user information, usually Excel table, the format is as follows


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7B/16/wKioL1bGxLGSrE0PAAA2gHQXdyg319.png "title=" Excel table. png "alt=" Wkiol1bgxlgsre0paaa2ghqxdyg319.png "/>


Note: In order to facilitate the import, I will The PowerShell correlation name corresponds to the value one by one in the table.

The Group organizational unit needs to be established in advance, or it can be used with PowerShell commands

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7B/17/wKiom1bGxBvy1z4oAAAZM-sanQo071.png "title=" Group organizational unit. PNG "alt=" Wkiom1bgxbvy1z4oaaazm-sanqo071.png "/>

User password I use the function to do, the number + letter is the best, but some alphanumeric, such as the number 0 and the Small Letter o and capital letter o, to the user and operations staff inconvenience, I use random numbers + fixed letters to do it.

2. Save the table as a suffix name . CSV Format file (the file will be separated by commas for each string value), if there is Chinese in the table, we will need to. The CSV file opens as text and saves or overwrites the file in UTF-8 encoded format .


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7B/16/wKioL1bGxMjDCaB3AAA3Yxhxikc053.png "title=" CSV file. png "alt=" Wkiol1bgxmjdcab3aaa3yxhxikc053.png "/>


3. The user Excel table preparation is finished, next, use the PowerShell command to bulk Import user information (if in the production environment or implementation environment, please test on the test machine is feasible and then import, Recommended to do some backup work before)

log on to the AD domain controller and execute as Administrator with PowerShell command

Import-csv ' C:\UserData\ADUserData.csv ' | Foreach-object {new-aduser-samaccountname $_. Samaccountname-surname $_. Surname-givenname$_. Givenname-name $_. Name-userprincipalname $_. Userprincipalname-displayname$_. Name-description $_. Name-path $_. Path-accountpassword (Convertto-securestring-asplaintext $_. Accountpassword-force)-enabled 1-changepasswordatlogon 1}


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7B/16/wKioL1bGxOnixKC5AACCSufsUEY617.png "title=" Import-csv.png "alt=" Wkiol1bgxonixkc5aaccsufsuey617.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7B/17/wKiom1bGxMDSwQemAAB1yFIGZw0998.png "title=" AD user. png "alt=" Wkiom1bgxmdswqemaab1yfigzw0998.png "/>


Note:

' C:\UserData\ADUserData.csv ' for import . CSV file path,new-aduser for Add New User command,-samaccountname$_. sAMAccountName is "- type $_. data Value " ,-enabled 1 is the account is enabled,-changepasswordatlogon 1 is the user must change the password the next time you log on, you can change it on your own request.

4. Batch user import, sometimes a small number of users did not import successfully, this time, we need to manually import a single user, the command is as follows:

New-aduser-name " week eight "-surname " week "-givenname " eight "-samaccountname "20160219008"- userPrincipalName "[email protected]"-displayname " week eight "-description " week eight "-path "ou= Technology Department , ou= user , ou=test,dc=test,dc=local "-accountpassword (convertto-securestring" [email protected] "-asplaintext- Force)-enabled$true-changepasswordatlogon $true

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7B/16/wKioL1bGxP3QIGz0AAA-mF9NVow136.png "title=" PowerShell single user import. png "alt=" Wkiol1bgxp3qigz0aaa-mf9nvow136.png "/>

Note:-enabled $true is to enable the account,-changepasswordatlogon$true for the user must change the password at the next login, Can be changed on request. When a single user is added, both values are executed with $true to succeed, for reasons unknown.


5. Attach the Excel file for the operation


This article is from the "dumb Bird does not fly" blog, please be sure to keep this source http://ostrich.blog.51cto.com/11191939/1743391

PowerShell Bulk Add Domain Users (Windows R2)

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.