Exchange Powershell – Automatic Mailbox Creation

By | May 28, 2014

As part of my project to automate user account creation for my school district, I have to make sure that mailboxes are created and up-to-date for our staff. We have a separate mailbox database for each department on our Exchange 2010 server, as well as a separate database for users who have departed. We often have users move between departments, and thus need their mailboxes moved with them to the appropriate database. For those who have departed, we mark their mailbox’s ‘hide from global address list’ flag and set them to only receive mail from our postmaster address, to avoid having the deactivated users’ mailboxes fill up with unnecessary mail. We retain users and their mailboxes for up to a year so that their information is guaranteed in our regular site backups.

To handle this aspect of the account automation, I came up with a couple of Powershell scripts. The first handles the above-mentioned requirements. It looks which mailbox database a user’s mailbox SHOULD reside in vs. which mailbox it is currently in. The database it should reside in is determined by a HashTable which I have map the potential mailbox Active Directory Organizational Units to mailbox databases. If the comparison differs, it generates a (suspended) move request. It also looks to see if the destination mailbox database is the departed users’ database or not and ensures sure that the ‘hide from global address list’ and ‘receive mail *only* from …’ options are set accordingly.

sync-mailboxes.ps1

Since initiating a mailbox move during normal hours can be disruptive to the user, I have a second script which runs only late at night. This script looks for existing suspended mailbox move requests and resumes them. It also looks for completed move requests and clears them.

complete-mailbox-move-requests.ps1

Leave a Reply

Your email address will not be published. Required fields are marked *


*