After Hours optimize

10 handy PowerShell scripts for Exchange 2010 administrators

Save time and effort knocking out complex Exchange admin tasks with the help of these ready-made PowerShell scripts.

Exchange Server 2010 includes numerous Exchange Management Shell cmdlets, but it also provides some PowerShell scripts that are designed to accomplish more complex tasks. In this article, I will tell you about 10 of the most useful scripts that are included with Exchange Server 2010. All these scripts can be found in the server's \Program Files\Microsoft\Exchange Server\V14\Scripts folder.

Note: This article is also available as a PDF download.

1: CheckInvalidRecipients.ps1

The CheckInvalidRecipients.ps1 script is designed to correct situations in which a recipient has two different SMTP addresses set as the primary address. If such a recipient is detected, this script will set the WindowsEmailAddress as the primary SMTP address.

You can also use this script to ensure that a distribution group is truly hidden if the HideDLMembershipEnabled attribute is set to true. Exchange 2010 has a bug in which the membership may not truly be hidden if the ReportToManagerEnabled, ReportToOriginatorEnabled, or SendOofMessageToOriginatorEnabled attributes are set to true. The script looks for such conditions and sets these attributes to false so that DL membership will remain hidden.

2: CollectOverMetrics.ps1

The CollectOverMetrics.ps1 script reads the Database Availability Group member's event logs and compiles a report of recent activity. The report indicates when databases were mounted or dismounted and when a failover has occurred, and it provides information about other relevant events, such as database moves.

All the events are written to a CSV file. Each line of the CSV file contains the event, the database identity, the time of the event, the server on which the database was mounted, the reason for the operation, and whether the operation was successful.

3:  CollectReplicationMetrics.ps1

The CollectReplicationMetrics.ps1 script can help you find out how well database replication is performing. When the script is run, it gathers real-time performance data by using Performance Monitor counters. The script compiles replication performance data from multiple mailbox servers and writes each server's data to a separate CSV file. You can specify individual servers to monitor or you can run the script against the entire Database Availability Group. Although the script creates a separate report for each server, it also creates a summary report named HaReplPerfReport.<timestamp>.csv

4: Install-AntispamAgents.ps1

One of the Edge Transport Server's jobs is to perform message hygiene by checking inbound and outbound messages for viruses and spam. However, smaller organizations often opt to save money by not deploying an Edge Transport Server. Instead, Internet mail is brought directly into the Hub Transport Server.

The Hub Transport Server performs the same types of message hygiene as an Edge Transport Server, but the anti-spam agents are not installed by default. You can install them by using the Install-AntispamAgents.ps1 script.

5: Export-OutlookClassification.ps1

Before Outlook can classify messages or report on message classifications, it needs to know which message classifications are in use in your Exchange organization. To determine this, run the Export-OutlookClassification script on your Exchange Server and redirect the output to an XML file. To do so, you can use a command like this one:

./Export-OutlookClassification.ps1 > C:\Classifications.xml

Once you have created the XML file, you must copy it to each user's computer. To complete the process, get Outlook to use the XML file by creating the following registry entries:


Keep in mind that editing the registry is dangerous and you can destroy Windows and / or your applications if you make a mistake. You should always create a full system backup prior to making any registry modifications.

6: MoveAllReplicas.ps1

Occasionally, you may need to decommission a public folder server and replace it with another server. While the process of removing the public folder replicas from the old server and creating the replicas on the new server can be done manually, Microsoft provides a script for the job: MoveAllReplicas.ps1.

To use this script, just supply the -Server switch, the name of the old server, the -NewServer switch, and the name of the new server. Here is an example of how to use the script:

.\MoveAllReplicas.ps1 -Server Server1 -NewServer Server2

7: MoveMailbox.ps1

If you've been working with Exchange 2007 or Exchange 2010 for awhile, you are no doubt familiar with the Move-Mailbox cmdlet. What you might not know is that Microsoft also provides a script named MoveMailbox.ps1.

At its simplest, this script requires you to provide the name of the mailbox you want to move and the identity of the target mailbox database. For example, if I wanted to move my own mailbox, the command might look like this:

.\MoveMailbox.ps1 -Identity ""  -TargetDatabase "DB2"

There are numerous variations to how this script can be used, and you can also use it in conjunction with pipelined input. This TechNet article provides more details on using this script.

8: MailboxDatabaseReseed.ps1

If you have problems with the replication in a Database Availability Group, your active and passive databases could fall out of sync. In extreme situations, you may need to reseed the passive database copy. You can accomplish the reseeding process using the MailboxDatabaseReseed.ps1 script. Reseeding the passive copy essentially removes the passive database copy and then rebuilds by replicating the Active database. Although you can reseed manually, this script simplifies the reseeding process.

9: Move-TransportDatabase.ps1

The message queues on a hub transport server rely on databases that are similar to mailbox databases and public folder databases. By default, Microsoft stores these databases on the Hub transport server at C:\Program Files\Microsoft\Exchange Server\V14\TransportRoles\Data\Queue.

If the server's C: drive begins running low on space, or if system performance becomes an issue, you many need to move the transport database to a new location. You can do this with the Move-TransportDatabase.ps1 script. You just need to provide a new database path and a new database logging path. For example, the command might look like this:

Move-TransportDatabase.ps1 -QueueDatabasePath D:\Exchsrvr -QueueDatabaseLoggingPath D:\Exchsrvr\logs

10: Get-SetupLog.ps1

Any time you install Exchange 2010, Setup creates a folder named C:\ExchangeSetupLogs. This folder contains numerous log files related to the installation process. Although you can read any of these log files using a text editor like Notepad, doing so can be cumbersome, to say the least. Microsoft has provided the Get-SetupLog.ps1 script to make reading the logs easier. When you run this script, important log entries are color-coded to indicate errors and warnings.


Brien Posey is a seven-time Microsoft MVP. He has written thousands of articles and written or contributed to dozens of books on a variety of IT subjects.