Create Multiple Users in Server 2008 with PowerShell, Part 2: More Fields

In our previous article, we showed you the fastest way to go from a simple list of users to their creation in Active Directory. However, you’ll frequently get a list of users that will have extra data fields. Since we can’t write a script ahead of time for every possible scenario, we’ll show you how to take our user creation PowerShell script and modify it to suit your purpose.

In this case, we’ve been given the Office attribute for our new users, so we’ll want to make sure that’s added in each of our new users account on creation.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 1

The first thing we do is to save the excel file as a .csv file.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 2

Next we open up the Active Directory Users and Computers snap-in. We need to find out what is the actual attribute name for the Office field, so we’ll open the properties of one of our current users by double-clicking on them.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 3

We can see that this user has Human Resources filled in for his Office attribute on the General tab.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 4

We’ll click on the Atribute Editor tab to find out the technical name for that Office field, because we are going to need this to enter into PowerShell in a minute. It shows that the Attribute name for the Office field is physicalDeliveryOfficeName. Since the Attribute name is not always the same as the Field name in the other tabs, it can be a little difficult sometimes to find what you are looking for. If you can’t seem to find the field you need, you can always create a dummy user and modify just that specific field to something unique, then go to the Attribute Editor tab and scroll down until you find it.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 5

Now we’ll need to edit our PowerShell script to reflect this new field. The format for this will be “AttributeName=dataRecord”. We want to make sure that we enter the field name correctly from our .csv file after the “$dataRecord.” entry. This section will pull the data from our users file:

$physicalDeliveryOfficeName=$dataRecord.Office

and this section of the script will put it into the new user objects:

$objUser.Put(“physicalDeliveryOfficeName”,$physicalDeliveryOfficeName)

The finished script will look like this:

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 6

Make sure to save the script as a .ps1 file.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 7

With our users list and our script in the C:UsersAdministrator folder, we right-click the script and choose Run with PowerShell.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 8

When we jump back over to AD Users and Computers, we can see out new users created.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 9

Opening up one of our newly created users will show that the Office field is filled out with the data from our original users list.

create-multiple-users-in-server-2008-with-powershell-part-2-more-fields photo 10

Creating multiple users with PowerShell is a very easy task, and with this knowledge at your fingertips, you’ll never sweat it again.

Article Create Multiple Users in Server 2008 with PowerShell, Part 2: More Fields compiled by Original article here

More stories

How to delete the Shutdown Event Tracker in Windows Server 2008

The Shutdown Event Tracker is a great tool for enterprise admins to keep track of server shutdowns. There’s been more than one experience where we’ve been troubleshooting a downed server, and it would have been extremely useful to know what was going through the mind of the person who shut it off.

Convert Virtually Any Audio Format with XRECODE II

With the amount of different portable audio devices and music software applications, sometimes it is difficult getting the correct formats. Today we take a look at XRECODE II which will convert virtually any audio file format to another.

Delete Flash Cookies to Stop Web Sites from Secretly Tracking You

If you like to keep your browsing private, you probably already clear your history and cookies after a session, but your tracks are not completely gone. There’s also another type of cookie to get rid of called Flash Cookies or Local Shared Objects (LSOs). Today we take a look at how to get rid of

Add Print & Print Preview Commands to Firefox’s Context Menu

Have you been thinking about how much easier it would be to having the Print & Print Preview commands in Firefox’s Context Menu? The Print Context Menu extension for Firefox allows you to avoid having to use the File Menu to access the print commands.

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.