Bulk create AD accounts using PowerShell

Bulk create objects using PowerShell.

John Savill

February 26, 2016

1 Min Read
Bulk create AD accounts using PowerShell

Q. How can I bulk create accounts in AD from a file?

A. Often you may want to perform bulk actions in PowerShell, creating accounts is just one example. An easy was is if you have a comma-separated value (CSV) file with the objects and attributes you wish to create. For example below is a CSV file for new accounts I want to create. An easy way to create this type of file is an export from a system or edit in something like Excel.

Name,SamAccountName,GivenName,Surname,DisplayName,DescriptionSteven Rogers,Steve,Steven,Rogers,Steven Rogers,Captain AmericaAnthony Stark,Tony,Anthony,Stark,Anthony Stark,Iron ManHenry Pym,Hank,Henry,Pym,Henry Pym,Ant-ManJanet van Dync,Janet,Janet,van Dyne,Jane van Dyne,WaspBruce Banner,Bruce,Bruce,Banner,Bruce Banner,Hulk

Note that the first line is the name of the attributes then each line in the file a separate instance.

The Import-CSV cmdlet will import data from a CSV than pass that data out to the pipeline which can then create the objects. In my example below I have the creation using the -passthru switch which sends the created AD object to the next line which adds the user to an AD group.

Import-CSV -Path $env:HOMEPATHDocumentsroster.csv |    New-ADUser -Enabled $true -AccountPassword $password `    -Path "OU=Avengers,DC=savilltech,DC=net" -PassThru |    Add-ADPrincipalGroupMembership -MemberOf CurrentRoster

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like