It’s that time of year again. Many students, administrators, faculty and IT professionals are headed back to school. In honor of the season, below is a quick how-to featuring two PowerShell commands in Windows Server 2008 R2.
Importing User Accounts into Active Directory from a CSV file with Import-CSV and New-ADUser
Step One: Prepare the CSV File
For the user file, we can use the same column headers as the traditional CSVDE data import. This way we are able to use the familiar headings, while taking advantage of features in the Import-CSV command in Windows Server 2008 R2. Follow the below steps if you need a list of available headings for use in your CSV file.
Open a Command Prompt on your Windows Server 2008 R2 server. At the Command Prompt, enter the following command:
csvde -d “cn=users,dc=domain,dc=com” -f c:\foldername\filename.csv
This command will export all the objects in your ‘Users’ container. The available CSVDE column headings will most likely exceed 100 (especially if you have Exchange 2007 or 2010 in your domain).
Now that we have a list of available column names, let’s get down to the business of building our CSV import file. Here’s my completely unimpressive example, but hey, it works.
The above example will import the user accounts into the default “Users” container in Active Directory.
Step Two: Import the CSV file
Navigate to the following console on your Windows 7 Administrator workstation, with the Remote Server Admin Tools (RSAT) installed, or on a Server 2008 R2 domain controller:
Start > Administrative Tools > Active Directory Module for Windows PowerShell
(If needed, you can download the RSAT tools for Windows 7 here.)
Now we run the following command:
Import-Csv <location of your csv file> | New-ADUser
Import-Csv c:\data\stu.csv | New-ADUser
If successful, you’ll receive the helpful… well, you won’t receive anything really. Except for another prompt – this is much better than a big red error.
The Active Directory aftermath:
The next level:
The above is enough to get us started, but there are many more options available for importing /creating / modifying Active Directory accounts using the New-ADUser command. Remember, as with all PowerShell commands, an excellent help file (man page) is available from the shell console. The following commands will show the full help files for the
New-ADUser and Import-CSV commands:
Get-Help New-ADUser -Full
Get-Help Import-Csv -Full
Good luck, and have fun!