Powershell Bulk import of AD accounts

Source: Internet
Author: User
Tags naming convention

It is a separate command line that imports a CSV file and uses the information in it to create dozens of or even hundreds of new Active Directory users:

Import-csv ' C:\provision1.csv ' | foreach-object {new-qaduser-organizationalunit ' company.pri/singers '-name ($_. ') First Name ' + '. ' + $_. ' Last Name ')-samaccountname $_. ' Logon name '-city$_.city-title $_. ' Job title '-department $_.department}

It's really a long command, but it's surprisingly powerful. The first is the Import-csv (Native Shell cmdlet), which simply reads a CSV file and returns the object. Each row in the CSV file is a separate object, and the columns of the CSV file become the properties of the object. In the Provision1.csv file, the column names are similar to "LogonName" and "first Name"-this is interesting because the column names do not map directly to the Active Directory user properties. I found that files, such as this one, are often used to sound familiar column names rather than Active Directory-specific names. After all, you may be receiving this file from someone in the personnel department of the company, and they are unlikely to know that last Name in Active Directory is actually the SN attribute.

Once all the data in the CSV file is imported and converted to objects, the objects are piped to the Foreach-object cmdlet, which executes the code block (the contents of the curly brace of the single-line command) for each object. That is, the script is executed once for each row in the CSV file. In this script, a special $_ variable is a reference to the current object (or the current line of the CSV file).

As you can see, for each object, I have executed the New-qaduser cmdlet. It is one of approximately more than 10 cmdlets in a Quest add-in. Name Qaduser worth paying attention to. As you may have guessed, Q represents Quest. This naming convention is designed to avoid conflicts with the ultimate version of the New-aduser cmdlet that the Microsoft Active Directory team may launch in the future. This way, if you load these two cmdlets into a shell at the same time, you and the shell will be able to differentiate them more easily.

The remainder of the single-line command contains parameters for the New-qaduser cmdlet. It first specifies OrganizationalUnit, which is where you want to create all the new users. Next is the Name property, which I have set to the contents of the first Name column, the period, and the contents of the last Name column.

The last interesting fact is that the city parameter actually changes the L attribute (or locality-name) in Active Directory. The cmdlet also accepts a parameter named L, which implements exactly the same functionality. In most cases, parameters that reference Active Directory properties can use the property name or text label of the Active Directory user and computer tools.


This article is from the "Xiang Zi" blog, please be sure to keep this source http://fengxiang.blog.51cto.com/531475/1752010

Powershell Bulk import of AD accounts

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.