Scripts for Creating Archive Mailboxes in Exchange 2010

Background Information

I had a client who has been running Exchange 2010 SP1 for some time and they have a little over 7,000 user mailboxes in their environment. Their environment consisted of 2 Exchange servers running the mailbox role and the user mailboxes were spread between the two servers. Each mailbox server had 12 mailbox databases (totalling 24) and it got to a point that they wanted to implement archiving for their users.

The client had already created 12 additional mailbox databases to host the archive mailboxes (these databases were placed on slower disks) so in total each server now has 24 databases (totalling 48 in the environment).

Client Requirements

The client wants to create mailboxes on the same server as the primary mailbox for each user mailbox. For example,  if USER2’s mailbox is on ExchangeSRV02 on database DB09, then this script will create an archive mailbox for USER2 on archive database ARCHIVEDB09

SCRIPT 1 – Create Archive for ALL mailboxes (Save this file as FileName.PS1)

$users = Get-Mailbox -RecipientTypeDetails usermailbox

foreach ($u in $users) {

$MailboxDatabase= (Get-Mailbox $U).Database

$ArchiveDatabase= “Archive”+ ( $MailboxDatabase.Name).Substring( 0)

Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase

write-host “Done processing $u…”

}

In an Exchange Powershell, simply run the script as FileName.PS1

SCRIPT 2 – Create Archive for selected mailboxes (Save this file as FileName.PS1)

As a modification to this script – if you have a list of names for the users who you want to have archive mailboxes, you can place these names in a text file (names.txt for example)

If ($Args.Count -eq 0) {
write-host “You need to specify a file with a list of users as a parameter at the command line!!!”
Exit
}
$users = get-content $args[0]
foreach ($u in $users) {
$MailboxDatabase= (Get-Mailbox $U).Database
$ArchiveDatabase= “Archive”+ ( $MailboxDatabase.Name).Substring( 0)
Enable-Mailbox $U -Archive -ArchiveDatabase $ArchiveDatabase
write-host “Done processing $u…”
}

In an Exchange Powershell, simply run the script as FileName.PS1 Names.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s