How to Create Multiple Users in Server 2008 with PowerShell

Creating users through the AD Users and Computers snap-in is a very easy process, but you’ll frequently face the situation where you need to create accounts for a whole group of people at once. There’s no need for this to be a time consuming process for you though, and we’ve done all the heavy lifting so you don’t have to.

We’ve just got a list of new employees from the HR Department, and they’ve been kind enough to give it to us in an excel format. Make sure that your own Excel file matches the same format, and make sure that you are using First Name and Last Name as column headers.

how-to-create-multiple-users-in-server-2008-with-powershell photo 1

The first thing we are going to do is save the file as a .csv, and to do that, we click on the Office Button and select Save As.

how-to-create-multiple-users-in-server-2008-with-powershell photo 2

We’re going to name our file users.csv, and make sure that we pick CSV (Comma delimited) in the Save as type box, and then click Save.

how-to-create-multiple-users-in-server-2008-with-powershell photo 3

Next we’ll create a new text document on the server where we’ll be doing the user creation.

how-to-create-multiple-users-in-server-2008-with-powershell photo 4

We’ll then copy the following into our new text document:

$objOU=[ADSI]"LDAP://OU=People,DC=sysadmingeek,DC=com" $dataSource=import-csv "users.csv" foreach($dataRecord in $datasource) { $cn=$dataRecord.FirstName + " " + $dataRecord.LastName $sAMAccountName=$dataRecord.FirstName + "." + $dataRecord.LastName $givenName=$dataRecord.FirstName $sn=$dataRecord.LastName $sAMAccountName=$sAMAccountName.ToLower() $displayName=$sn + ", " + $givenName $userPrincipalName=$sAMAccountName + "@sysadmingeek.com" $objUser=$objOU.Create("user","CN="+$cn) $objUser.Put("sAMAccountName",$sAMAccountName) $objUser.Put("userPrincipalName",$userPrincipalName) $objUser.Put("displayName",$displayName) $objUser.Put("givenName",$givenName) $objUser.Put("sn",$sn) $objUser.SetInfo() $objUser.SetPassword("P@assw0rd") $objUser.psbase.InvokeSet("AccountDisabled",$false) $objUser.SetInfo() }

In the first line, make sure that you enter the correct information for your domain and the OU where you are creating the users. You’ll want to update the @sysadmingeek.com line as well to match your domain.

how-to-create-multiple-users-in-server-2008-with-powershell photo 5

We then want to save the file as a PowerShell script, so we change the Save as type: to All Files (*), and name it PSusersScript.ps1.

how-to-create-multiple-users-in-server-2008-with-powershell photo 6

Now we need to prep PowerShell to run scripts. You can launch PowerShell by clicking on the shortcut in the taskbar, or by typing PowerShell in the quick search box.

how-to-create-multiple-users-in-server-2008-with-powershell photo 7

We need to change the Execution Policy to allow scripts to be run remotely, so we type

set-executionpolicy remotesigned

When prompted, we type Y and then hit enter to execute.

how-to-create-multiple-users-in-server-2008-with-powershell photo 8

Now that we’ve allowed the script to be run, we need to place both the users.csv and the PSusersScript.ps1 files in our folder for execution. Since the PowerShell prompt naturally comes up to the root user folder, and we are logged on as Administrator, we are going to place them in the C:UsersAdministrator folder. When both files are in the folder, we right-click on the PSusersScript.ps1 file and choose Run with PowerShell.

how-to-create-multiple-users-in-server-2008-with-powershell photo 9

If we take a look in AD Users and Computers, you will now see all those new users you just created.

how-to-create-multiple-users-in-server-2008-with-powershell photo 10

The new users will be created in the lastname.firstname format, but the script could easily be altered to your need. Now that you’ve already created the script, all you have to do in the future is to place your list of users in the C:UsersAdministrator folder and run the PowerShell script. Easy!

More stories

What is a Productive Geek?

In the digital age, there are countless tools to help keep you productive, but using them effectively is a whole different story. The Productive Geek is somebody who learns to use those tools to actually save time and get things done.

Add the Recycle Bin to the Taskbar in Windows 7

When you’re busy multi-tasking on your PC, sometimes getting to the Recycle Bin can a pain. Today we take a look at a couple of different methods for adding the Recycle Bin to your Taskbar for easier access.

Friday Fun: Open Doors

Hopefully many of you have today off so you can go shopping for your favorite geeky toys. If the boss made you come in today, or you need a break from the in-laws, take some time to play the puzzle game Open Doors.

How To Install Windows Server 2008 R2

Windows Server 2008 R2 is the latest version of Microsoft’s Windows Server operating system. Microsoft tries their best to make each task as simple as possible, and Server 2008 R2 is a shining example of that goal in action. We’re going to take you through a basic install and show you just how easy

Our Look at Microsoft Office 2010 Beta

Just when you were getting used to using the new Ribbon feature in Office 2007, it’s now time to take a look at Office 2010. Right now it’s in Beta stage and we’ll show you how it looks and what you can expect.