Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roachhd/596aea22f3efa2a11dc4 to your computer and use it in GitHub Desktop.
Save roachhd/596aea22f3efa2a11dc4 to your computer and use it in GitHub Desktop.
bulk-creating-ad-users-from-excel-sheets
Active Directory

To create a large number of new Active Directory users, you can import the user data from a CSV file, for example export an Excel sheet to CSV.

Next, this piece of code will turn the CSV data into real Active Directory user accounts:

Import-Csv -Path F:\userlist.csv -UseCulture -Encoding Default |
ForEach-Object {
  
  $_.AccountPassword = $_.AccountPassword | 
                           ConvertTo-SecureString -Force -AsPlainText
  $_ 

} |
New-ADUser -WhatIf 

All the CSV file needs are column headers that represent the parameters expected by New-ADUser. A very trivial list could use headers like this:

Name,SamAccountName,Description,Company,City,Path,AccountPassword

Just notice that CSV files by nature can only submit string data types. Since the property AccountPassword needs to be a SecureString datatype, the PowerShell code takes the string from the CSV file and converts it to SecureString before the data is handed over to New-ADUser.

This technique can be used to polish any raw data before you use it to create the user.


Power Tip #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment