Using a Template to Create Recipient Objects

Last Update: Sep 04, 2024 | Published: Apr 01, 2009

SHARE ARTICLE

Introduction

In previous articles, I showed you how creating a mailbox template could reduce the amount of work that you have to do in the future when creating new Exchange Mailboxes, all the while making the mailbox creation process less prone to error. That’s just the beginning of what templates are capable of doing though. In this article, I want to show you how you can use templates to create multiple mailboxes simultaneously.

Building a CSV FileU

sing a template simplified the process of creating a mailbox, but there was still some work that you had to do. Although the template filled in a lot of the particulars, you still has to provide the mailbox name, the user principle name, the name of the Exchange Server and the database that would be used to store the mailbox, the organizational unit, and of course the name of the template that you want to base the mailbox on.

If after reading my first article, you were thinking that it would be easier to just create mailboxes in the old fashion way, you are right. Of course that’s assuming that you are only creating one mailbox. If you have multiple mailboxes to create, then the process is far easier if you use the template.

Of course the template can’t do everything all by itself. We need a way of providing Exchange with the necessary information about the mailboxes that we are going to create. The easiest way to do this is to create a Comma Separated Value (CSV) file.

You can create a CSV file manually using Notepad, but it is usually easier to use Microsoft Excel. If you look at Figure A, you can see the beginnings of a spreadsheet that I am going to use in conjunction with my template to create new mailboxes. The first thing that I want to show you is the top row of the spreadsheet, which contains my column headings. This row is extremely important, because without it, Exchange won’t know how to interpret the data in the file.

Figure A
using_a_template_to_create_recipient_objects_part_2-1
The spreadsheet’s header row is very important.

The first piece of information that we are providing is the name of the user account for which the mailbox will be created. Next, we need to provide the User Principle Name (UPN). For all practical purposes, this is the user’s E-mail address. After that, we are providing the user’s Organizational Unit (OU). This is the Active Directory container where the user’s account resides. Finally, we are providing a password for the user.

I mentioned earlier that it was easier to create the necessary CSV file using Excel than it was to create the file manually. Part of the reason for that is that Excel allows you to copy and paste a cell’s contents. The OU and Password fields will be the same for all of our user accounts, so we can just copy and paste them, rather than having to retype them each time. You can see what the completed spreadsheet looks like in Figure B.

Figure B
using_a_template_to_create_recipient_objects_part_2-2
This is what our completed spreadsheet looks like.

Now, click on the Excel orb (or Jewel, or whatever Microsoft is calling it this week), and choose the Save As | Other Formats option from the menu. Save the spreadsheet as a CSV file named Users.csv. Figure C shows what the file looks like in CSV format.

Figure C
using_a_template_to_create_recipient_objects_part_2-3
This is what our spreadsheet looks like in CSV format.

Finally, copy the CSV file to your Exchange Server, and open the Exchange Management Shell. The first thing that you must do is to define your template as a template instance named $Template. To do so, enter the following command:

$Template = Get-Mailbox “Template”

Next, we need to import the CSV file and tell Exchange how to use the fields that it contains. You can do so by entering the following command:

Import-CSV “C:NewUsers.csv” | ForEach-Object -process {$Temp = ConvertTo-SecureString $_.Password -asPlainText -force;New-Mailbox -Name $_.Name -UserPrincipalName $_.UPN -OrganizationalUnit $_.OU -Database “Mailbox Database” -Password $Temp -TemplateInstance $Template}

You can see what these commands look like in action in Figure D.

Figure D
using_a_template_to_create_recipient_objects_part_2-4
This is what it looks like when we create new user accounts using the template.

If we open the Exchange Management Console and go to the Recipient Configuration | Mailbox container, we can verify that the new mailboxes have been created, as shown in Figure E.

Figure E
using_a_template_to_create_recipient_objects_part_2-5
The Exchange Management Console verifies the existence of the new mailboxes.

Conclusion

If you attempted to type the commands shown above, you probably realized how tedious it is to enter them. Keep in mind though, that you can easily turn these commands into a script. After doing so, creating new users becomes a matter of simply updating your CSV file and then running the script.

SHARE ARTICLE