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.
The first thing we do is to save the excel file as a .csv file.
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.
We can see that this user has Human Resources filled in for his Office attribute on the General tab.
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.
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:
and this section of the script will put it into the new user objects:
The finished script will look like this:
Make sure to save the script as a .ps1 file.
With our users list and our script in the C:UsersAdministrator folder, we right-click the script and choose Run with PowerShell.
When we jump back over to AD Users and Computers, we can see out new users created.
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.
Creating multiple users with PowerShell is a very easy task, and with this knowledge at your fingertips, you’ll never sweat it again.