Exchange server: Exclude a database from Auto Provisioning or Create Mailboxes in bulk using script.

M AService Manager
CERTIFIED EXPERT
Most Valuable Expert2017 and 2020.
O365, Exchange Server,Windows Server, Active Directory, Virtualization, Teams and Email Migration Expert.
Published:
Edited by: Andrew Leniart
This article will explain how to exclude a database when creating a mailbox.  I.e. Exchange will exclude it from automatic provisioning. Also, how to create mailboxes in bulk using a CSV file.

Exclude database from auto-provisioning

When mailboxes are created in Exchange Server (2010 and above), you have the option of selecting an existing database to host the new mailbox. However, if you create the mailbox without specifying a database, the mailbox will be created in the default mailbox database.

For example, if you have two databases;
  

Run the following command to check which of your current databases have been excluded from auto-provisioning.

Get-MailboxDatabase | select Identity,IsExcludedFromProvisioning

If you want to exclude one database from automatic provisioning of new mailboxes, then run the following command;

Set-MailboxDatabase "Mailbox-Database-users" -IsExcludedFromProvisioning $True


Create mailboxes in bulk.

If you want to create mailboxes in bulk and then select the respective databases, the following script will allow you to achieve that.

Step1.
Create a CSV file as shown in the following spreadsheet screenshot.

Ensure the file is saved with a CSV extension (.csv). I used mailboxcreation as the file name. 
I.e. mailboxcreation.csv as shown in the next screenshot.


Step2. Create the mailboxes in bulk using the CSV file created


Open an elevated Exchange Management Shell and run the following command to save the new password to variable "$Password" to be used in a new mailboxes creation.
$Password=Read-Host “Please enter password” –AsSecureString


Run the following command to create mailboxes in bulk using the value saved in variable $Password. 

This will create users in the "UsersOU in Active Directory. You may change the OU based on your AD structure.

Import-CSV "c:\mailboxeslis.csv" | ForEach {New-Mailbox -Name $_.name -firstname $_.firstname -lastname $_.lastname -userPrincipalName $_.userprincipalname -OrganizationalUnit Users -Password $Password}

Please run the following command to identify which database mailbox is created. Take one user from the CVS file created earlier. 

Get-Mailbox Testingcreation | fl Name,database

You have now created a mailbox in the CVS file which is not hosted in "Mailbox-Database-users" and is excluded from auto-provisioning in the above step.
 
Thanks for reading my article. 
 
I have also written other articles that explain Exchange administration for all versions of Exchange (see below):




0
3,070 Views
M AService Manager
CERTIFIED EXPERT
Most Valuable Expert2017 and 2020.
O365, Exchange Server,Windows Server, Active Directory, Virtualization, Teams and Email Migration Expert.

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.