Bulk create user accounts

by Mitch Tulloch [Published on 12 April 2016 / Last Updated on 12 April 2016]

A tip on how you can use Windows PowerShell to bulk-create user accounts in a Windows Server 2012 Active Directory environment.

Here's a tip showing how you can use Windows PowerShell to bulk-create user accounts in a Windows Server 2012 Active Directory environment. The tip is excerpted from my latest book Training Guide: Installing and Configuring Windows Server 2012 from Microsoft Press:
http://www.wservernews.com/go/1369910837647

A good example of how Windows PowerShell can be used to automate a common Active Directory management task is the bulk creation of users. For example, you can combine the previous examples with the Import-Csv cmdlet which allows you to read in data from a comma-separated values file (CSV), to create multiple user accounts in a single operation.

To illustrate this, the file new-users.csv contains a line of header information followed by attributes for three user accounts as follows:

Name,GivenName,Surname,SamAccountName,UserPrincipalName
Arno Bost,Arno,Bost,abost,abost@corp.contoso.com
Peter Fischer,Peter,Fischer,pfischer,pfischer@corp.contoso.com
Manish Chopra,Manish,Chopra,mchopra,mchopra@corp.contoso.com

The following command reads the CSV file and pipes its contents into the New-ADUser cmdlet, sets the password for each user account as Pa$$w0rd, and ends by enabling the accounts:

PS C:\> Import-Csv C:\data\new-users.csv | New-ADUser -PassThru | `
Set-ADAccountPassword -Reset `
-NewPassword (ConvertTo-SecureString -AsPlainText "Pa$$w0rd" -Force) `
-PassThru | Enable-ADAccount

The highlighted portion of this command takes the string "Pa$$w0rd" and converts it from plain text to a secure string so that it can be used by the -NewPassword parameter of the Set-ADAccountPassword cmdlet. The -Force parameter is needed to suppress the confirmation prompt generated by use of the -AsPlainText parameter.

The above tip was previously published in an issue of WServerNews, a weekly newsletter from TechGenix that focuses on the administration, management and security of the Windows Server platform in particular and cloud solutions in general. Subscribe to WServerNews today by going to http://www.wservernews.com/subscribe.htm and join almost 100,000 other IT professionals around the world who read our newsletter!

Mitch Tulloch is an eleven-time recipient of the Microsoft Most Valuable Professional (MVP) award and a widely recognized expert on Windows Server and cloud computing technologies.  Mitch is also Senior Editor of WServerNews. For more information about him see http://www.mtit.com.

 

See Also


The Author — Mitch Tulloch

Mitch Tulloch is a well-known expert on Windows Server administration and cloud computing technologies. He has published over a thousand articles on information technology topics and has written, contributed to or been series editor for over 50 books.