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:
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:
Arno Bost,Arno,Bost,abost,[email protected]
Peter Fischer,Peter,Fischer,pfischer,[email protected]
Manish Chopra,Manish,Chopra,mchopra,[email protected]
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.