Microsoft’s PowerShell is a task automation and configuration management framework that combines a scripting language with a command-line shell. Acting as a crucial component of Exchange Server administration, it assists administrators to perform the routine Exchange database and configuration and administrative jobs.
You can use PowerShell commands to carry out various Exchange database management activities that go beyond the Exchange Admin Center (EAC). These commands help admins to mount, dismount, create, move, and manage mailbox databases.
They also manage Database Availability Groups (DAG) and perform health checks. Moving on with the topic, this post explores various useful PowerShell commands for efficient database management
PowerShell commands for database management
Here is an insight into various commands that admins use for streamlined management of Exchange database:
Mailbox database configuration
The PowerShell commands assist in several routine tasks associated with the mailbox database:
- Database creation
- Modification of database settings
- Ensuring proper database configuration
Let’s know about these PowerShell commands in detail.
New-MailboxDatabase
This cmdlet will create a new mailbox database or a recovery database. Every database created through this command will have a distinct name.
Example: New-MailboxDatabase -Server Server01 -Name “DBX01” -EdbFilePath D:\ExchangeDatabases\DBX01\DBX01.edb
This example creates a mailbox database DBX01 on the Exchange Server Server01 to store the EDB file DBX01.edb at the provided location.
Get-MailboxDatabase
This command retrieves mailbox database objects from a server or organization
Example: Get-MailboxDatabase -Identity MBXDB01 -Status | Format-List
This example will show the information about the mailbox database named MBXDB01 in a list format. This will include details of mount state, status, available whitespace, and other crucial details about the mailbox database.
Set-MailboxDatabase
This cmdlet changes the operational settings and configuration of the mailbox database..
Example: Set-MailboxDatabase “Mailbox DB01” -DeletedItemRetention 7.00:00:00
In this example, the cmdlet Set-MailboxDatabase sets the duration of 7 days as retention fo the mailbox database named Mailbox DB01.
Move-DatabasePath
The command shifts the database and the associated log files to another server location.
Example: Move-DatabasePath -Identity MyDB01 -EdbFilePath C:\MyDBFolder\MyDB01.edb
This example safely moves the mailbox database named MyDB01 to a new location. To perform this operation, you should temporarily dismount the database.
Routine database operations
These commands help in performing database mounting and dismounting operations. Before starting these tasks, check the database state by using Eseutil command: Eseutil /mh <Your Database>.edb.
A clean shutdown state will indicate that the database is ready for mounting if all required Exchange services are working correctly.
Mount-Database
It will mount the mailbox database on the Exchange server when services, such as Microsoft Exchange Replication and Microsoft Exchange Information Store are running.
Example: Mount-Database -Identity MyDB01
This example mounts the database named MyDB01 on the Exchange server
Dismount-Database
The cmdlet will dismount a mailbox database when the Microsoft Exchange Information Store service is in active state.
Example: Dismount-Database -Identity MyDB01
This example dismounts the database named MyDB01
Database Monitoring and Reporting
These PowerShell cmdlets get the data about the usage, health, and statistics of the mailbox database.
Get-MailboxStatistics
It fetches details about a specific mailbox, which include:
- Size of the mailbox
- Number of messages included in the mailbox
- The recent most access time of the mailbox
- Completed mailbox move request
Example 1: Get-MailboxStatistics -Identity MarSh
This example returns the mailbox statistics of the user Mary Sheldon through its associated alias MarSh.
Example 2: Get-MailboxStatistics -Server MBxServer01
This example shows the mailbox statistics for all mailboxes stored in the MbxServer01 server.
Get-MailboxDatabaseCopyStatus
Checks the information regarding status and health of the mailbox database copies
Example 1: Get-MailboxDatabaseCopyStatus -Identity DBX01 | Format-List
This example fetches the status information for all the copies of the database named DBX01.
Example 2: Get-MailboxDatabaseCopyStatus -Server MBX01 | Format-List
This example shows the status for all the database copies on the mailbox server named MBX01.
Example 3: Get-MailboxDatabaseCopyStatus -Identity DB01\MBX01 | Format-List
This command shows the status of the copy of database DB01 existing on the mailbox server MBX01.
In all these examples, the format-list parameter gives the result in a list format.
Manage Exchange database copies within DAG environment
These commands will take care of replication and copies of databases within the Database Availability Group (DAG)
Add-MailboxDatabaseCopy
This cmdlet creates a passive copy of an already existing active mailbox database. The target Exchange server should satisfy the following conditions:
- A healthy member of the same DAG
- Does not have any preexisting copy of the database
- Has the required database path available
Example:
Add-MailboxDatabaseCopy -Identity DB01 -MailboxServer MBX01 -ReplayLagTime 00:10:00 -TruncationLagTime 00:15:00 -ActivationPreference 2
This example creates a passive copy of the mailbox database DB01 to the mailbox server MBX01. The configured values are as follows:
- Replay lag time: 10 minutes
- Truncation lag time: 15 minutes
- Activation preference: 2
Remove-MailboxDatabaseCopy
This cmdlet removes the passive mailbox database copy but avoids removing any active copy of the database. The latter is possible only if you delete all the passive database copies and then delete the active copy by using the Remove-MailboxDatabase cmdlet.
Example: Remove-MailboxDatabaseCopy -Identity DB01\MBX01
This example removes a mailbox database copy of the database named DB01 from the mailbox server MBX01.
Update-MailboxDatabaseCopy
It helps to seed or reseed a copy of a mailbox database.
Example: Update-MailboxDatabaseCopy -Identity DB01\MBX01
This example copies the mailbox database DB01 and its log files from an active database copy to a passive database copy. The motive is to start or resume replication on the mailbox server MBX01.
Test-ReplicationHealth
This cmdlet checks all the information about replay and replication services for a mailbox server in a DAG environment.
Example: Test-ReplicationHealth -Identity MBX01
This example checks the replication health for the mailbox server named MBX01.
Using Exchange server recovery software
All these commands help to manage Exchange databases, mailboxes and the contained items. You can use them to perform mount dismount operations in Exchange database or to use commands to monitor or generate report for the database health, etc. However, in case of corrupt or inaccessible database, native Exchange management tools may not work properly. Instead, you can end up losing your sensitive data stored in the database. The need is to ensure safe data recovery through a foolproof method. This is where Exchange recovery software such as Stellar Repair for Exchange can be a viable option.
Conclusion
When carrying out database management, the Exchange management administrator should be aware of al the necessary PowerShell commands. For example, the admin should be aware about the working of the Mount-Database and Dismount-Database cmdlets.
The admin should have practical knowledge of the Get-MailboxDatabase cmdlet and the New-MailboxDatabase cmdlet. Practical knowledge of many other commands, such as Get-MailboxStatistics, Get-MailboxDatabaseCopyStatus, Add-MailboxDatabaseCopy, and Test-ReplicationHealth is equally essential.
But, these commands may not help the admin to produce the expected results in case of a corrupt or an inaccessible or database.
The ultimate need in such a case is to retrieve your sensitive data at the earliest, which is where an Exchange server recovery software can be of much help. Of the multiple applications available online, Stellar Repair for Exchange is an effective recover option in this regard.


