<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Exchange Server Pro &#187; PowerShell</title>
	<atom:link href="http://exchangeserverpro.com/tag/powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://exchangeserverpro.com</link>
	<description>Microsoft Exchange Server News - Tips - Tutorials</description>
	<lastBuildDate>Wed, 23 May 2012 11:55:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to Set Up an Automated Exchange 2010 Database Backup Alert Email</title>
		<link>http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email</link>
		<comments>http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email#comments</comments>
		<pubDate>Mon, 30 Apr 2012 13:11:21 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Mailbox Server]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4242</guid>
		<description><![CDATA[Learn how to use PowerShell to automatically monitor your Exchange Server 2010 database backups and send an alert email when recent backups have not been successful.]]></description>
			<content:encoded><![CDATA[<p>In recent articles I&#8217;ve taken you step by step through some techniques for <a href="http://exchangeserverpro.com/powershell-how-to-send-email">sending email from PowerShell scripts</a>. If you haven&#8217;t read those articles yet you can find them here:</p>
<ul>
<li><a href="http://exchangeserverpro.com/powershell-how-to-send-email">Part 1 – How to Send SMTP Email Using PowerShell</a></li>
<li><a href="http://exchangeserverpro.com/powershell-email-message-body">Part 2 - How to Add a Message Body to Emails Sent from Scripts</a></li>
<li><a href="http://exchangeserverpro.com/powershell-send-html-email">Part 3 - How to Add a HTML Message Body to Emails Sent from Scripts</a></li>
<li><a href="http://exchangeserverpro.com/powershell-html-email-formatting">Part 4 - How to Create Formatted HTML Output from Scripts</a></li>
</ul>
<p>I also shared with you a script that can be used to <a href="http://exchangeserverpro.com/powershell-script-check-exchange-2010-database-backups">check Exchange Server 2010 database backups</a> and alert you to any that have not had a recent backup.</p>
<p>Now it&#8217;s time to bring all of that information together and demonstrate how you can set up an automated database backup alert email for your <a href="http://exchangeserverpro.com">Exchange Server 2010</a> environment.</p>
<p>The two components of this are:</p>
<ul>
<li>The PowerShell script itself (we&#8217;ll use the one mentioned earlier but with some modifications to email-enable it)</li>
<li>Task Scheduler for automatically running the script each day</li>
</ul>
<h2>Script for Exchange Server 2010 Database Backup Email Alerts</h2>
<p>To email-enable the script I&#8217;ve made just a few modifications. The original script used this conditional logic to display the report in the PowerShell window.</p>
<pre>#If alert flag is true output the report
if ($alertflag -eq $true )
{
	Write-Host "The following databases have not been backed up in" $threshold "hours."
	$alerts | ft -AutoSize
}
else
{
	Write-Host "No backup alerts required."
}</pre>
<p>To change this to send an email alert we can use this code instead:</p>
<pre>#If alert flag is true send the email alert
if ($alertflag -eq $true )
{
	#HTML styles for nice formatting
        $style = "&lt;style&gt;BODY{font-family: Arial; font-size: 10pt;}"
	$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
	$style = $style + "TH{border: 1px solid black; background: #CC0000; padding: 5px; color: #FFFFFF;}"
	$style = $style + "TD{border: 1px solid black; padding: 5px; }"
	$style = $style + "&lt;/style&gt;"

        #SMTP options for sending the report email
	$smtpServer = "ho-ex2010-caht1.exchangeserverpro.net"
	$smtpFrom = "reports@exchangeserverpro.net"
	$smtpTo = "administrator@exchangeserverpro.net"
	$messageSubject = "Exchange Backup Alerts"

        $intro = "The following databases have not been backed up in " + $threshold + " hours.&lt;BR&gt;&lt;BR&gt;"
	$report = $alerts | ConvertTo-Html -Fragment

	#Get ready to send email message
	$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
	$message.Subject = $messageSubject
	$message.IsBodyHTML = $true
	$message.Body = ConvertTo-Html -Body "$intro $report" -Head $style

	#Send email message
	$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
	$smtp.Send($message)

}</pre>
<p>If any parts of that don&#8217;t make sense just refer to the previous tutorials on sending email with PowerShell.</p>
<p class="alert"><strong>Download the script file here:</strong> <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Get-DailyBackupAlerts.zip" title="Version 1.0 downloaded 199 times" >Get-DailyBackupAlerts.ps1</a> (downloaded 199 times so far)</p>
<p>If you&#8217;re using this script in your environment you will need to change the SMTP options to suit.</p>
<pre>
#SMTP options for sending the report email
$smtpServer = "ho-ex2010-caht1.exchangeserverpro.net"
$smtpFrom = "reports@exchangeserverpro.net"
$smtpTo = "administrator@exchangeserverpro.net"
$messageSubject = "Exchange Backup Alerts"
</pre>
<p>Save the script as <strong>Get-DailyBackupAlerts.ps1</strong> in a folder called <strong>C:\Scripts</strong> on the server where you would like it to run each day. Note that the script depends on the Exchange Server 2010 management tools, so they will also need to be installed.</p>
<h2>Using Task Scheduler to Run PowerShell Scripts</h2>
<p>Now we need to configure the scheduled task in Task Scheduler. On a Windows Server 2008 server you&#8217;ll find this in the <strong>Administrative Tools</strong>. After you&#8217;ve launched Task Scheduler click on <strong>Create Task</strong>.</p>
<p><img class="aligncenter size-full wp-image-4243" title="task-scheduler-powershell-script-01" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/task-scheduler-powershell-script-01.jpg" alt="" width="305" height="290" />Give the task a meaningful name, set it to <strong>Run whether user is logged on or not</strong>, and also if necessary change the user account that it will run as (you may wish to create a special Exchange administrative account with a strong password for running these types of scripts).</p>
<p><img class="aligncenter size-full wp-image-4244" title="task-scheduler-powershell-script-02" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/task-scheduler-powershell-script-02.jpg" alt="" width="590" height="439" />On the <strong>Triggers</strong> tab click new and add a <strong>Weekly</strong> trigger for each of your normal business days that you want the script to run (eg Monday &#8211; Friday). Set the <strong>Start</strong> time to suit your normal backups finishing time and your own work schedule.</p>
<p><img class="aligncenter size-full wp-image-4245" title="task-scheduler-powershell-script-03" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/task-scheduler-powershell-script-03.jpg" alt="" width="556" height="439" /></p>
<p>On the <strong>Actions</strong> tab click <strong>New</strong> and add an action of Start a program. Configure the program of <strong>powershell.exe</strong> and the arguments <strong>-command &#8220;c:\scripts\get-dailybackupalerts.ps1&#8243;</strong></p>
<p><img class="aligncenter size-full wp-image-4248" title="task-scheduler-powershell-script-04" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/task-scheduler-powershell-script-04.jpg" alt="" width="552" height="428" /></p>
<p>&nbsp;</p>
<p>Click <strong>OK</strong> to finish creating the new task. You will be prompted to enter the credentials for the account that you configured the task to run as.</p>
<p>Now you can test the scheduled task by right-clicking on it in the Task Scheduler Library and choosing <strong>Run</strong>.</p>
<p><img class="aligncenter size-full wp-image-4247" title="task-scheduler-powershell-script-05" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/task-scheduler-powershell-script-05.jpg" alt="" width="503" height="244" />Assuming you have some databases that have not backed up recently you should receive an alert email shortly after running the scheduled task.</p>
<p><em>Note: if your backups are all up to date you can test the script by changing the <strong>$threshold</strong> variable to something very low such as <strong>1</strong>.</em></p>
<p><img class="aligncenter size-full wp-image-4249" title="exchange-2010-backup-alert-email" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/exchange-2010-backup-alert-email.jpg" alt="" width="590" height="229" /></p>
<p class="alert"><strong>Download the script file here:</strong> <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Get-DailyBackupAlerts.zip" title="Version 1.0 downloaded 199 times" >Get-DailyBackupAlerts.ps1</a> (downloaded 199 times so far)</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/powershell-script-check-exchange-2010-database-backups" title="PowerShell Script: Check Exchange 2010 Database Backups">PowerShell Script: Check Exchange 2010 Database Backups</a></li><li><a href="http://exchangeserverpro.com/powershell-script-check-exchange-mailbox-database-backup-time" title="PowerShell Script: Check Exchange Mailbox Database Last Backup Time">PowerShell Script: Check Exchange Mailbox Database Last Backup Time</a></li><li><a href="http://exchangeserverpro.com/avoid-running-transaction-log-disk-space-exchange-servers" title="Avoid Running Out of Transaction Log Disk Space on Exchange Servers">Avoid Running Out of Transaction Log Disk Space on Exchange Servers</a></li><li><a href="http://exchangeserverpro.com/test-mailflow-exchange-2003-servers" title="Using Test-Mailflow with Exchange 2003 Servers">Using Test-Mailflow with Exchange 2003 Servers</a></li><li><a href="http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server" title="How to Health Check an Exchange 2010 Mailbox Server">How to Health Check an Exchange 2010 Mailbox Server</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email">How to Set Up an Automated Exchange 2010 Database Backup Alert Email</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange</title>
		<link>http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility</link>
		<comments>http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility#comments</comments>
		<pubDate>Mon, 23 Apr 2012 13:41:32 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Update Rollups]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4743</guid>
		<description><![CDATA[How to use the CustomPatchInstallerActions.ps1 to avoid problems installing update rollups on Exchange servers that have Forefront installed]]></description>
			<content:encoded><![CDATA[<p>When Microsoft recently released the <a href="http://exchangeserverpro.com/update-rollup-2-exchange-2010-service-pack-2">latest update rollup for Exchange Server 2010</a> a few disgruntled customers left comments about the situation with Exchange update rollups and Forefront Protection for Exchange.</p>
<p>If you&#8217;re not a Forefront user or you&#8217;re otherwise unaware of the situation, the issue is that Forefront Protection for Exchange and update rollups don&#8217;t play nicely together. For example during installation the update rollup can hang at stages such as restarting the Exchange services after the update has been applied.</p>
<div id="attachment_4744" class="wp-caption aligncenter" style="width: 600px"><img class="size-full wp-image-4744" title="Services not starting after Exchange Server rollup installation" src="http://exchangeserverpro.com/wp-content/uploads/2012/04/exchange-2010-installing-updates-forefront-fscutility-01.jpg" alt="Services not starting after Exchange Server rollup installation" width="590" height="351" /><p class="wp-caption-text">Services not starting after Exchange Server rollup installation</p></div>
<p>This is why each update rollup release comes with the following instructions:</p>
<blockquote><p>Note for Forefront Protection for Exchange users For those of you running Forefront Protection for Exchange, be sure you perform these important steps from the command line in the Forefront directory before and after this rollup&#8217;s installation process. Without these steps, Exchange services for Information Store and Transport will not start after you apply this update. Before installing the update, disable ForeFront by using this command: fscutility /disable. After installing the update, re-enable ForeFront by running fscutility /enable.</p></blockquote>
<p>As a result we see comments like these from disgruntled customers.</p>
<blockquote><p>Note for Forefront Protection for Exchange users: We still don&#8217;t care enough about you to add two lines to the setup script. Instead you have to do it manually. Or you can install the update via Microsoft Update and you&#8217;ll be in for a funny surprise.</p>
<p>Hey Microsoft&#8230;. could you not detect for your own software and automatically run the command fscutility /disable????, Now I cannot even get WUS to do this…. Annoyed! and feeling unappreciated as a FF customer</p></blockquote>
<p>Microsoft actually has <a href="http://blogs.technet.com/b/exchange/archive/2010/06/02/3410046.aspx">provided a solution for this</a>, back when Exchange Server 2007 SP2 was released, and appears to have carried it forward for Exchange Server 2010 as well. A script named <strong>CustomPatchInstallerActions.ps1</strong> can be used to perform pre- and post-installation tasks for update rollups.</p>
<p>I&#8217;m not sure why they don&#8217;t refer to it with each update rollup release, but as far as I can tell from my own testing it works fine.</p>
<p>Here is what you need to do.</p>
<ol>
<li>In the <strong>\Scripts</strong> folder of your Exchange 2010 installation find the file named <strong>CustomPatchInstallerActions.ps1.template</strong></li>
<li>Create a new sub-folder in \Scripts named <strong>Customizations</strong></li>
<li>Copy the script template into that sub-folder, and remove the <strong>.template</strong> extension</li>
<li>Edit the file with the customizations you want, and the next time you install an update rollup the script will be called automatically</li>
</ol>
<p>So what kind of customizations should you include? I did a little testing and here is what I suggest as a minimum. You&#8217;ll also find Microsoft&#8217;s advice <a href="http://support.microsoft.com/kb/929080">here</a>.</p>
<p>First, I ran <strong>fscutility /disable</strong> (from the <strong>C:\Program Files (x86)\Microsoft Forefront Protection for Exchange Server</strong> folder) to see what happens. I received the following output.</p>
<pre>Error:
  Microsoft Forefront Protection cannot be disabled at this time.  Please stop
  the following services and then rerun this utility.

   FSCController
   MSExchangeTransport
   MSExchangeIS</pre>
<p>So clearly some services need to be stopped first. That will need to go in the script.</p>
<p>After disabling those services <strong>fscutility /disable</strong> works successfully. So that can be run second.</p>
<pre>  Removing dependencies...

      dependency on FSCController removed from Microsoft Exchange Information Store
      dependency on FSEIMC removed from Microsoft Exchange Transport Service
      Microsoft Exchange Transport Service Agent registration removed

Status:  Microsoft Forefront Protection NOT Integrated.</pre>
<p>In the custom script itself the actions to perform before installing an update rollup go in the <strong>PrePatchInstallationActions</strong> function.</p>
<pre>function PrePatchInstallActions
{
                Log "Running PrePatchInstallActions"

		Log "Stopping services"
		Stop-Service FSCController,MSExchangeTransport,MSExchangeIS -Force

		Log "Disabling Forefront"
		$fscutility = "C:\Program Files (x86)\Microsoft Forefront Protection for Exchange Server\fscutility.exe"
		Invoke-Expression $fscutility /disable

}</pre>
<p>Notice I&#8217;ve also made use of the Log function that is in the script so that I can see in the log file later that my custom actions were run (or at least attempted to run). The log file is written to <strong>C:\ExchangeSetupLogs\CustomPatchInstallActions.log</strong></p>
<p>After the update rollup is finished installing there is a similar process involved to re-enable Forefront. These steps go in the <strong>PostPatchInstallActions</strong> function.</p>
<pre>function PostPatchInstallActions
{
                Log "Running PostPatchInstallActions"

		Log "Stopping services"
		Stop-Service FSCController,MSExchangeTransport,MSExchangeIS -Force

		Log "Enabling Forefront"
		$fscutility = "C:\Program Files (x86)\Microsoft Forefront Protection for Exchange Server\fscutility.exe"
		Invoke-Expression $fscutility /enable

		Log "Starting services"
		Start-Service FSCController,MSExchangeTransport,MSExchangeIS

}</pre>
<p>When I upgraded two servers side-by-side, one with the <strong>CustomPatchInstallerActions.ps1</strong> and one without, the one with the script updated without any problems and the one without hung while trying to start the services afterwards.</p>
<p>So in my testing this appears to work well, but it is something you should test in your own environment before relying on it too heavily.</p>
<p>Note that this script can be used for all kinds of situations even when Forefront is not installed. If you have any pre- or post-install actions required in your environment (eg running the <a href="http://exchangeserverpro.com/how-to-install-updates-on-exchange-server-2010-database-availability-groups">StartDagServerMaintenance.ps1</a> script, disabling backups, disabling other antivirus software, <a href="http://exchangeserverpro.com/powershell-how-to-send-email">sending an email alert</a> to your team) you can include those in this <strong>CustomPatchInstallerActions.ps1</strong> script.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script" title="PowerShell Script to Generate Email Traffic in a Test Lab Environment">PowerShell Script to Generate Email Traffic in a Test Lab Environment</a></li><li><a href="http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server" title="How to Health Check an Exchange 2010 Mailbox Server">How to Health Check an Exchange 2010 Mailbox Server</a></li><li><a href="http://exchangeserverpro.com/list-users-access-exchange-mailboxes" title="How to List all Users Who Have Access to Other Exchange Mailboxes">How to List all Users Who Have Access to Other Exchange Mailboxes</a></li><li><a href="http://exchangeserverpro.com/generate-html-report-exchange-2010-environment" title="How to Generate a HTML Report of Your Exchange 2010 Environment">How to Generate a HTML Report of Your Exchange 2010 Environment</a></li><li><a href="http://exchangeserverpro.com/powershell-script-check-exchange-mailbox-database-backup-time" title="PowerShell Script: Check Exchange Mailbox Database Last Backup Time">PowerShell Script: Check Exchange Mailbox Database Last Backup Time</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility">Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</title>
		<link>http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell</link>
		<comments>http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell#comments</comments>
		<pubDate>Fri, 13 Apr 2012 12:52:32 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Message Tracking]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4706</guid>
		<description><![CDATA[How to generate a summary of the message tracking events that have occurred on Exchange Server 2010 using PowerShell.]]></description>
			<content:encoded><![CDATA[<p>A useful report to generate from the <a href="http://exchangeserverpro.com/exchange-2010-message-tracking">Exchange Server 2010 message tracking logs</a> is a summary of the different message tracking events that have occurred.</p>
<p>Each message tracking log entry records an event ID from <a href="http://technet.microsoft.com/en-us/library/cc539064.aspx">the following list</a>:</p>
<ul>
<li>BADMAIL</li>
<li>DELIVER</li>
<li>DSN</li>
<li>EXPAND</li>
<li>FAIL</li>
<li>POISONMESSAGE</li>
<li>RECEIVE</li>
<li>REDIRECT</li>
<li>RESOLVE</li>
<li>SEND</li>
<li>SUBMIT</li>
<li>TRANSFER</li>
</ul>
<p>Each event means different things. Healthy messages may record multiple receive, send, transfer, submit or deliver events, depending on your environment. Unhealthy messages may record badmail or fail events.</p>
<p>While there is no hard and fast rules about what percentage of each event you should see, it is still useful to take a look at a summary of the different events IDs in case you notice something that may warrant further investigation.</p>
<p>You can generate this summary using <a href="http://exchangeserverpro.com/powershell">PowerShell</a> and the <a href="http://technet.microsoft.com/en-us/library/aa997573.aspx">Get-MessageTrackingLog</a> cmdlet.</p>
<pre>[PS] C:\&gt;Get-MessageTrackingLog -ResultSize Unlimited | Group-Object -Property:EventId | Sort-Object Count -Desc | Select Name,Count

Name        Count
----        -----
RECEIVE     58679
DELIVER     47496
NOTIFYMAPI  20812
SUBMIT      20806
SEND        19863
RESUBMIT     8679
HAREDIRECT   6826
TRANSFER      351
DSN            96
FAIL           95
SUBMITDEFER     6
BADMAIL         2</pre>
<p>For more tips and examples on <a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell">searching message tracking logs with PowerShell</a> check out <a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell">this article</a>.</p>
<p>Incidentally you may find this type of summary report to be faster to generate using Log Parser instead. In my tests the PowerShell command took almost 5 minutes to complete, whereas Log Parser took only 9 seconds on the same server. Your mileage may vary. You can check out the Log Parser query <a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-log-parser">here</a>.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell" title="Searching Exchange Server 2010 Message Tracking Logs with PowerShell">Searching Exchange Server 2010 Message Tracking Logs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/calculate-hourly-email-traffic-using-message-tracking-log-parser" title="Calculate Hourly Email Traffic using Message Tracking Logs and Log Parser">Calculate Hourly Email Traffic using Message Tracking Logs and Log Parser</a></li><li><a href="http://exchangeserverpro.com/daily-email-traffic-message-tracking-log-parser" title="Calculate Daily Email Traffic using Message Tracking Logs and Log Parser">Calculate Daily Email Traffic using Message Tracking Logs and Log Parser</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-log-parser" title="Reporting Exchange Server 2010 Message Tracking Event IDs with Log Parser">Reporting Exchange Server 2010 Message Tracking Event IDs with Log Parser</a></li><li><a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010" title="Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports">Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell">Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Searching Exchange Server 2010 Message Tracking Logs with PowerShell</title>
		<link>http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell</link>
		<comments>http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell#comments</comments>
		<pubDate>Sat, 31 Mar 2012 15:35:09 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Message Tracking]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4660</guid>
		<description><![CDATA[How to use the power and flexibility of PowerShell to perform searches of Exchange Server message tracking logs.]]></description>
			<content:encoded><![CDATA[<p>In my introduction to <a href="http://exchangeserverpro.com/exchange-2010-message-tracking">Exchange Server 2010 message tracking</a> I wrote that <a href="http://exchangeserverpro.com/powershell">PowerShell</a> provides one of the most useful and powerful ways to search message tracking logs.</p>
<p>Although the message tracking log explorer is fine for simple searches on a single server, it doesn&#8217;t work so well when you want to do wildcard searches, search multiple servers at once, or export data for further analysis.</p>
<div id="attachment_4673" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4673" title="exchange-2010-message-tracking-toolbox-04" src="http://exchangeserverpro.com/wp-content/uploads/2012/03/exchange-2010-message-tracking-toolbox-041.jpg" alt="Message tracking log exporer" width="580" height="330" /><p class="wp-caption-text">Message tracking log explorer</p></div>
<p>For those operations PowerShell is the way to go, and frankly once you&#8217;ve seen how powerful PowerShell is for message tracking log searches you&#8217;ll probably never use the explorer tool again.</p>
<h2>Getting Started with Searching Message Tracking Logs Using PowerShell</h2>
<p>Message tracking log searches are performed in the <a href="http://exchangeserverpro.com/exchange-2010-install-management-tools">Exchange Management Shell</a> by running the <a href="http://technet.microsoft.com/en-us/library/aa997573.aspx">Get-MessageTrackingLog</a> cmdlet. You can run this cmdlet with no parameters on any Edge Transport, Hub Transport or Mailbox server and it will return all of the log entries on that server.</p>
<pre>[PS] C:\&gt;Get-MessageTrackingLog

EventId    Source      Sender                                 Recipients                               MessageSubject
-------    ------      ------                                 ----------                               --------------
RECEIVE    SMTP        Ivana.Ferrary@exchangeserverpro.net    {Ana.Williams@exchangeserverpro.net}     Luminary asep...
DELIVER    STOREDRIVER John.Tilleray@exchangeserverpro.net    {Lucy.Spratley@exchangeserverpro.net}    Egress concor...
RECEIVE    STOREDRIVER Ambrine.Berry@exchangeserverpro.net    {Lorraine.Oza@exchangeserverpro.net}     Brazen
DELIVER    STOREDRIVER Ivana.Ferrary@exchangeserverpro.net    {Ana.Williams@exchangeserverpro.net}     Luminary asep...
RECEIVE    SMTP        Donna.A'Bear@exchangeserverpro.net     {Marc.Itoje@exchangeserverpro.net}       Garble expedi...
RECEIVE    SMTP        Priya.Smith@exchangeserverpro.net      {Melanie.Thomas@exchangeserverpro.net}   Enthral boorish
DELIVER    STOREDRIVER Donna.A'Bear@exchangeserverpro.net     {Marc.Itoje@exchangeserverpro.net}       Garble expedi...
RECEIVE    SMTP        Jane.Martin@exchangeserverpro.net      {Charlotte.Bonsey@exchangeserverpro.net} Palate causti...
DELIVER    STOREDRIVER Ambrine.Berry@exchangeserverpro.net    {Lorraine.Oza@exchangeserverpro.net}     Brazen
RECEIVE    SMTP        Yvette.Willis@exchangeserverpro.net    {Jan.Marway@exchangeserverpro.net}       Malign edible
DELIVER    STOREDRIVER Priya.Smith@exchangeserverpro.net      {Melanie.Thomas@exchangeserverpro.net}   Enthral boorish
RECEIVE    STOREDRIVER Joy.Singh@exchangeserverpro.net        {Mary.Friel@exchangeserverpro.net}       Obfuscate
HAREDIRECT ROUTING     Joy.Singh@exchangeserverpro.net        {Mary.Friel@exchangeserverpro.net}       Obfuscate
....</pre>
<p>You can also search a remote server using the <strong>-Server</strong> parameter. This is useful when you are running the search from your own admin workstation or a separate management server.</p>
<pre>[PS] C:\&gt;Get-MessageTrackingLog -Server HO-EX2010-MB2</pre>
<p>The Get-MessageTrackingLog cmdlet also accepts input from the pipeline. This is a very convenient way to perform searches on multiple servers at once. For example to search all Hub Transport servers at once:</p>
<pre>[PS] C:\&gt;Get-TransportServer | Get-MessageTrackingLog</pre>
<p>Sometimes you may wish to search the transport servers only within a particular site. Because I might need to work with that list in a few different commands I&#8217;ll usually collect those into a variable first, for example all Hub Transport servers in the &#8220;HeadOffice&#8221; site:</p>
<pre>[PS] C:\&gt;$hubs = Get-ExchangeServer | Where {$_.Site -like "*HeadOffice" -and $_.IsHubTransportServer -eq $true}</pre>
<p>I can then pipe that array of servers into the Get-MessageTrackingLog cmdlet.</p>
<pre>[PS] C:\&gt;$hubs | Get-MessageTrackingLog</pre>
<h2>Remember Default Resultsize of 1000</h2>
<p>Often you will be running message tracking log searches that return a lot of results. However, by default the cmdlet will return only 1000 results.</p>
<p>Because of this you should try to get in to the habit of using the <strong>-Resultsize</strong> parameter to return unlimited results when running Get-MessageTrackingLog.</p>
<pre>[PS] C:\&gt;Get-TransportServer | Get-MessageTrackingLog -Resultsize unlimited</pre>
<h2>Run Long Queries Once by Collecting Results in a Variable</h2>
<p>When you&#8217;re performing investigative searches of your message tracking logs, particularly across multiple servers, those queries can take a long time to return the results. If you then found you needed to adjust the query, for example to be more specific, or to format the results in a different way, you have to wait a long time for the query to run a second time as well.</p>
<p>So a good tip is to always collect your query results into a variable, particularly very broad queries that take a long time to run, so that you can pick apart the collected data without having to re-run the query.</p>
<p>For example, if I want to investigate reports of email problems sending to Alan Reid, I can run one broad query across all Hub Transport servers and collect the results in a variable I will call <strong>$msgs</strong>.</p>
<pre>[PS] C:\&gt;$msgs = Get-TransportServer | Get-MessageTrackingLog -Recipients "Alan.Reid@exchangeserverpro.net" -resultsize unlimited</pre>
<p>I&#8217;ve now got thousands of records that I can begin to filter and dissect in different ways without having to re-run my query.</p>
<pre>[PS] C:\&gt;$msgs.count
13297</pre>
<p>For example I can find the top 10 senders to Alan Reid within seconds, instead of re-running the entire Get-MessageTrackingLog search again.</p>
<pre>[PS] C:\&gt;$msgs | Group-Object -Property Sender | Select-Object name,count | sort count -desc | select -first 10 | ft -auto

Name                                  Count
----                                  -----
Andrea.Sharma@exchangeserverpro.net     110
Richard.Bennett@exchangeserverpro.net   108
Judy.Mollo@exchangeserverpro.net        104
Ferzana.King@exchangeserverpro.net      102
Debra.Lowe@exchangeserverpro.net        100
Nicola.Noad@exchangeserverpro.net       100
Diane.Hall@exchangeserverpro.net         96
Caroline.Ball@exchangeserverpro.net      96
Chris.Majumdar@exchangeserverpro.net     96
Hugh.Sharma@exchangeserverpro.net        96</pre>
<p>According to <a href="http://technet.microsoft.com/en-us/library/ee176899.aspx">Measure-Command</a> the above command took 1.3 seconds to complete, whereas the re-running the full log search again would take 47.4 seconds. By collecting the results into a variable the first time all of the subsequent analysis of that data is able to be performed much faster.</p>
<h2>Each Single Message is Multiple Log Entries</h2>
<p>You&#8217;ll notice as you begin looking at message tracking logs that each individual email message generates multiple log entries. This is because each message goes through multiple events in the process of getting from sender to recipient, that the number of events will vary depending on how the message needs to be routed throughout your organization, as well as whether it is successfully delivered or not.</p>
<p>So a single email message may record a series of events such as:</p>
<pre>EventId  Source   Sender                            Recipients                        MessageSubject
-------  ------   ------                            ----------                        --------------
RECEIVE  SMTP     Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
DEFER    STORE... Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
DUPLI... STORE... Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
RECEIVE  STORE... Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
DELIVER  STORE... Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
RESUBMIT DUMPSTER Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
TRANSFER STORE... Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish
SEND     SMTP     Famida.Ghtoray@exchangeserverp... {Alan.Reid@exchangeserverpro.net} Prolix apropos embellish</pre>
<h2>Dealing with System.String[] in Exported Message Tracking Log Data</h2>
<p>At some stage you will want to export some message tracking log data to CSV for further analysis in Excel. If you were to pipe the output above into the <a href="http://technet.microsoft.com/en-us/library/ee176825.aspx">Export-CSV</a> cmdlet you will notice that some of the fields, such as Recipients, will appear as <strong>System.String[]</strong> in the output file.</p>
<div id="attachment_4677" class="wp-caption aligncenter" style="width: 390px">problem&#8221;]<img class="size-full wp-image-4677 " title="message-tracking-export-csv-system-string-01" src="http://exchangeserverpro.com/wp-content/uploads/2012/04/message-tracking-export-csv-system-string-01.jpg" alt="The Export-CSV System.String problem" width="380" height="233" /><p class="wp-caption-text">The Export-CSV System.String problem</p></div>
<p>To resolve this issue you need to first pipe your Get-MessageTrackingLog results into <a href="http://technet.microsoft.com/en-us/library/dd315291.aspx">Select-Object</a> and select the Recipients and RecipientStatus fields like this:</p>
<pre>... | Select-Object eventid,sender,timestamp,@{Name="Recipients";Expression={$_.recipients}},@{Name="RecipientStatus";Expression={$_.recipientstatus}},messagesubject | Export-CSV filename.csv</pre>
<p>This will give you the correct exported data.</p>
<div id="attachment_4678" class="wp-caption aligncenter" style="width: 593px"><img class="size-full wp-image-4678" title="message-tracking-export-csv-system-string-02" src="http://exchangeserverpro.com/wp-content/uploads/2012/04/message-tracking-export-csv-system-string-02.jpg" alt="Correct Recipient and RecipientStatus output" width="583" height="229" /><p class="wp-caption-text">Correct Recipients and RecipientStatus output</p></div>
<h2>Examples of Message Tracking Log Searches</h2>
<p>In the next part of this article series I&#8217;ll cover some specific examples of message tracking log searches using PowerShell.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell" title="Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell">Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/calculate-hourly-email-traffic-using-message-tracking-log-parser" title="Calculate Hourly Email Traffic using Message Tracking Logs and Log Parser">Calculate Hourly Email Traffic using Message Tracking Logs and Log Parser</a></li><li><a href="http://exchangeserverpro.com/daily-email-traffic-message-tracking-log-parser" title="Calculate Daily Email Traffic using Message Tracking Logs and Log Parser">Calculate Daily Email Traffic using Message Tracking Logs and Log Parser</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-log-parser" title="Reporting Exchange Server 2010 Message Tracking Event IDs with Log Parser">Reporting Exchange Server 2010 Message Tracking Event IDs with Log Parser</a></li><li><a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010" title="Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports">Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell">Searching Exchange Server 2010 Message Tracking Logs with PowerShell</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return</title>
		<link>http://exchangeserverpro.com/user-logged-mailbox-data-return</link>
		<comments>http://exchangeserverpro.com/user-logged-mailbox-data-return#comments</comments>
		<pubDate>Fri, 23 Mar 2012 13:05:05 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Mailboxes]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4631</guid>
		<description><![CDATA[When running Get-MailboxStatistics against a new mailbox you receive a warning instead of an expected result.]]></description>
			<content:encoded><![CDATA[<p>A reader asks:</p>
<blockquote><p>I have been trying to get a script that can log into mailboxes automatically. The reason is that I have 500 mailboxes and when I attempt to query their statistics I get an error that the mailbox has never been logged into and therefore can&#8217;t generate any stats.</p></blockquote>
<p>Let&#8217;s take a quick look at the issue itself. When a new mailbox is created and you attempt to use <a href="http://technet.microsoft.com/en-us/library/bb124612.aspx">Get-MailboxStatistics</a> to query the mailbox, you will receive a warning similar to this.</p>
<blockquote><p>WARNING: The user hasn&#8217;t logged on to mailbox &#8216;exchangeserverpro.net/Company/Branch Office/Users/Blake Johnson&#8217;<br />
(&#8217;0971ff8e-d6d1-4bd6-98b9-384b35103a2d&#8217;), so there is no data to return. After the user logs on, this longer appear.</p></blockquote>
<p><img class="aligncenter size-full wp-image-4634" title="user-hasnt-logged-on-to-mailbox" src="http://exchangeserverpro.com/wp-content/uploads/2012/03/user-hasnt-logged-on-to-mailbox.jpg" alt="" width="580" height="42" /></p>
<p>In itself this is not a problem, but it might produce undesirable results for some <a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010">mailbox reporting tasks</a>, or at the very least make them a little more difficult.</p>
<p>The idea of creating a script that automatically logs on to new mailboxes is one approach to solving the problem. However it is probably more difficult than another solution which is also available.</p>
<p>That other solution is to simply <a href="http://exchangeserverpro.com/powershell-how-to-send-email">send the mailbox an email</a>. Once you do that the Get-MailboxStatistics cmdlet will return a result for the mailbox like this:</p>
<pre>[PS] C:\&gt;get-mailbox blake.johnson | Get-MailboxStatistics | ft -auto

DisplayName   ItemCount StorageLimitStatus LastLogonTime
-----------   --------- ------------------ -------------
Blake Johnson 1                 BelowLimit</pre>
<p>But is it practical to send 500 mailboxes an email? If it is a test lab you could simply add them all to one distribution group, and send that group an email. It would take just a few moments.</p>
<p>If it is a production system and new mailboxes are created regularly, you can automate the task. MVP Pat Richard has written a PowerShell script that can be run as a scheduled task to <a href="http://www.ehloworld.com/175">automatically send a welcome email to new mailboxes</a>. You can customize the welcome message to provide useful information to new users on the network. It really is a great idea if you ask me, plus it solves this issue with mailbox reporting. Check out Pat&#8217;s script <a href="http://www.ehloworld.com/175">here</a>.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010" title="Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports">Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</a></li><li><a href="http://exchangeserverpro.com/calculate-exchange-2010-mailbox-sizes-powershell" title="How to Calculate Exchange 2010 Mailbox Sizes with PowerShell">How to Calculate Exchange 2010 Mailbox Sizes with PowerShell</a></li><li><a href="http://exchangeserverpro.com/reconnect-disconnected-mailbox-exchange-server-2010" title="How to Reconnect a Disconnected Mailbox in Exchange Server 2010">How to Reconnect a Disconnected Mailbox in Exchange Server 2010</a></li><li><a href="http://exchangeserverpro.com/move-exchange-mailboxes-text-file-powershell" title="How to Move Exchange Mailboxes in a Text File using PowerShell">How to Move Exchange Mailboxes in a Text File using PowerShell</a></li><li><a href="http://exchangeserverpro.com/counting-exchange-server-2010-mailboxes-powershell" title="Counting Exchange Server 2010 Mailboxes with PowerShell">Counting Exchange Server 2010 Mailboxes with PowerShell</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/user-logged-mailbox-data-return">The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/user-logged-mailbox-data-return/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerShell Script to Generate Email Traffic in a Test Lab Environment</title>
		<link>http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script</link>
		<comments>http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script#comments</comments>
		<pubDate>Mon, 19 Mar 2012 12:50:57 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4599</guid>
		<description><![CDATA[This PowerShell script will automatically generate email traffic within an Exchange Server 2010 test lab environment.]]></description>
			<content:encoded><![CDATA[<p>For a long time now I&#8217;ve wanted to write a script that would automatically generate email traffic within an <a href="http://exchangeserverpro.com">Exchange Server</a> test lab environment.</p>
<p>Having realistic email traffic within a test lab environment means you can do such real world activities as:</p>
<ul>
<li>test backup and recovery scenarios</li>
<li>learn how to use message tracking logs</li>
<li>test archiving solutions</li>
</ul>
<p>In the past I&#8217;ve used some simple VBScripts that just sent random messages via SMTP as a way to fill up test lab mailboxes. That approach had some disadvantages though. The scripts I wrote only sent a stream of email messages at a single rate rather than at varying rates through the day as you would see in the real world. They also filled up inboxes only, never putting the messages in the Sent Items folder for the From address.</p>
<p>So last week I got to work creating a new <a href="http://exchangeserverpro.com/powershell">PowerShell</a> script to generate the email traffic. I <a href="http://exchangeserverpro.com/forums/powershell-corner/1210-building-test-lab-email-traffic-generator-script-powershell.html">tracked some of the development in the forums</a> and can now share the complete script here.</p>
<p>This script does require some setting up before you run it, so please read the instructions to get it working in your test lab. I have only written and tested this script for <a href="http://exchangeserverpro.com/training">Exchange 2010 training</a> lab environments on the assumption that most people will be training for the latest version of Exchange.</p>
<p class="alert">Before we go further let me be absolutely clear that this script is for <strong>test lab environments only</strong>. Under no circumstances should you attempt to run this script in a production environment.</p>
<h2>Using the Start-MailGen.ps1 Script in Your Test Lab</h2>
<p>The scripts uses the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=C3342FB3-FBCC-4127-BECF-872C746840E1&amp;amp;displaylang=en&amp;displaylang=en">Exchange Web Services Managed API</a> so the first step is to <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=C3342FB3-FBCC-4127-BECF-872C746840E1&amp;amp;displaylang=en&amp;displaylang=en">download</a> and install that on your test lab server.</p>
<div id="attachment_4601" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4601" title="ews-api" src="http://exchangeserverpro.com/wp-content/uploads/2012/03/ews-api.jpg" alt="EWS Managed API" width="580" height="286" /><p class="wp-caption-text">EWS Managed API</p></div>
<p>Next, download the script and extract the three files to your server. I placed mine in C:\Scripts\MailGen.</p>
<p class="alert">Download the script file here: <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Mailgen.zip" title="Version 1.0 downloaded 292 times" >Start-MailGen.ps1</a> (downloaded 292 times so far)</p>
<p>Open the Start-MailGen.ps1 file in the PowerShell editor or in Notepad and check the following items.</p>
<p>The $dllfolderpath variable is set to the default installation path for the EWS Managed API v1.1. If you install a different version, or to a different path, update this variable.</p>
<pre>#Path to the Exchange Web Services DLL
$dllfolderpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"</pre>
<p>The script uses a switch statement to determine how many emails to send each hour of the day. These values are what I use but you can change them up or down to suit your test lab. The hours 6am to 7pm are individually specified, and then the default value at the end is used for the remaining hours of the day.</p>
<pre>06 {$sendcount = 50}
07 {$sendcount = 80}
08 {$sendcount = 600}
09 {$sendcount = 600}
10 {$sendcount = 800}
11 {$sendcount = 1000}
12 {$sendcount = 600}
13 {$sendcount = 600}
14 {$sendcount = 800}
15 {$sendcount = 800}
16 {$sendcount = 900}
17 {$sendcount = 400}
18 {$sendcount = 200}
19 {$sendcount = 80}
default {$sendcount = 10}</pre>
<p>You can just specify even numbers like the above because the script varies the send count further by adding a random number each time. This will give you a realistic level of email traffic through the different hours of the day.</p>
<div id="attachment_4604" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4604" title="email-graph" src="http://exchangeserverpro.com/wp-content/uploads/2012/03/email-graph.jpg" alt="Sample email traffic graph" width="580" height="325" /><p class="wp-caption-text">Sample email traffic graph</p></div>
<p>The service account that will be running the script needs impersonation rights granted to it. I run mine as Administrator since it is just a test lab. Open the Exchange Management Shell and run the following command to grant the impersonation rights.</p>
<pre>[PS] C:\&gt;New-ManagementRoleAssignment -Name:impersonationAssignmentName -Role:ApplicationImpersonation -User:administrator</pre>
<p>You may also need to set your script execution policy to unrestricted.</p>
<pre>[PS] C:\&gt;Set-ExecutionPolicy Unrestricted</pre>
<p>Also, as the script file was downloaded from the internet you may need to right-click the file and choose <strong>Properties</strong>, and then click the <strong>Unblock</strong> button.</p>
<p>The script also depends on the Active Directory remote administration tools. These should be installed already on an Exchange 2010 mailbox server, but if you&#8217;re running the script from a non-Exchange server you may need to install them.</p>
<p>Finally, to start generating email traffic open the Exchange Management Shell and run the script.</p>
<pre>[PS] C:\Scripts\Mailgen&gt;.\Start-MailGen.ps1</pre>
<p>The script begins to send email and will show a progress indicator.</p>
<div id="attachment_4605" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4605" title="exchange-2010-test-lab-email-generator" src="http://exchangeserverpro.com/wp-content/uploads/2012/03/exchange-2010-test-lab-email-generator.jpg" alt="Start-MailGen.ps1 running" width="580" height="243" /><p class="wp-caption-text">Start-MailGen.ps1 running</p></div>
<p>The script will select a random sender and recipient from the available mailboxes in your test lab environment, and then construct a random email message using the two files that are provided with the script.</p>
<p>After sending the applicable number of emails for that hour of the day the script will sleep for 5 minute blocks until it reaches the next hour, and will start sending again.</p>
<p>You can leave the script running for several days if you wish, or set it as a scheduled task to ensure that it starts up again if the server is rebooted.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility" title="Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange">Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange</a></li><li><a href="http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server" title="How to Health Check an Exchange 2010 Mailbox Server">How to Health Check an Exchange 2010 Mailbox Server</a></li><li><a href="http://exchangeserverpro.com/list-users-access-exchange-mailboxes" title="How to List all Users Who Have Access to Other Exchange Mailboxes">How to List all Users Who Have Access to Other Exchange Mailboxes</a></li><li><a href="http://exchangeserverpro.com/generate-html-report-exchange-2010-environment" title="How to Generate a HTML Report of Your Exchange 2010 Environment">How to Generate a HTML Report of Your Exchange 2010 Environment</a></li><li><a href="http://exchangeserverpro.com/powershell-script-check-exchange-mailbox-database-backup-time" title="PowerShell Script: Check Exchange Mailbox Database Last Backup Time">PowerShell Script: Check Exchange Mailbox Database Last Backup Time</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script">PowerShell Script to Generate Email Traffic in a Test Lab Environment</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Exchange Server 2010 Email Address Policies</title>
		<link>http://exchangeserverpro.com/exchange-server-2010-email-address-policies</link>
		<comments>http://exchangeserverpro.com/exchange-server-2010-email-address-policies#comments</comments>
		<pubDate>Wed, 22 Feb 2012 13:29:35 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Email Address Policies]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4488</guid>
		<description><![CDATA[Learn how email address policies work in Exchange Server 2010, as well as examples for creating new policies in both the console and shell.]]></description>
			<content:encoded><![CDATA[<p>There is a project running at the company I work for to separate one of the areas of the business into their own entity. Among other things this rebranding exercise also includes changing their primary email addresses.</p>
<p>For several versions of <a href="http://exchangeserverpro.com">Exchange Server</a> now we&#8217;ve had the capability to manage email addresses for recipients by using policies. In Exchange Server 2010 these are referred to as <a href="http://technet.microsoft.com/en-us/library/bb232171.aspx">Email Address Policies</a>.</p>
<p>In this article I&#8217;ll provide an overview of the key concepts of email address policies and demonstrate some examples of how they can be used.</p>
<h2>The Exchange Server 2010 Default Email Address Policy</h2>
<p>Any Exchange 2010 organization will have one email address policy named &#8220;Default Policy&#8221;. You can view this in the <a href="http://exchangeserverpro.com/exchange-2010-install-management-tools">Exchange Management Console</a> under <strong>Organization Configuration -&gt; Hub Transport</strong>, in the <strong>Email Address Policies</strong> tab.</p>
<div id="attachment_4489" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4489" title="exchange-2010-email-address-policies-01" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-01.jpg" alt="Exchange 2010's default email address policy" width="580" height="155" /><p class="wp-caption-text">Exchange 2010&#39;s default email address policy</p></div>
<p>One of my gripes with managing email address policies in the console is that you can&#8217;t open a <strong>Properties</strong> view to see how they are configured. However you can right-click and choose <strong>Edit</strong> to achieve the same outcome.</p>
<p>The first thing you&#8217;ll notice that the default policy is not scoped to any particular recipient container, so it will apply to any object in Active Directory. The other thing you&#8217;ll notice is that the policy will apply to &#8220;All recipient types&#8221;, not a limited subset of the available types such as mailboxes, contacts, or groups.</p>
<div id="attachment_4490" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-4490" title="exchange-2010-email-address-policies-02" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-02.jpg" alt="Scope of the default email address policy in Exchange 2010" width="580" height="364" /><p class="wp-caption-text">Scope of the default email address policy in Exchange 2010</p></div>
<p>At the next dialog you get a chance to preview the results of the conditions in the email address policy.</p>
<div id="attachment_4491" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-4491" title="exchange-2010-email-address-policies-03" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-03.jpg" alt="" width="460" height="186" /><p class="wp-caption-text">Previewing the results of email address policy conditions</p></div>
<p>If you preview the default email address policy you should see all mail-enabled objects in the organization returned.</p>
<p><img class="aligncenter size-full wp-image-4492" title="exchange-2010-email-address-policies-04" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-04.jpg" alt="" width="445" height="422" /></p>
<p>At the next dialog you&#8217;ll see the email addresses that the policy will apply to those recipients that fall within the scope of the policy.</p>
<div id="attachment_4493" class="wp-caption aligncenter" style="width: 482px"><img class="size-full wp-image-4493" title="exchange-2010-email-address-policies-05" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-05.jpg" alt="Email addresses applied by the default email address policy" width="472" height="165" /><p class="wp-caption-text">Email addresses applied by the default email address policy</p></div>
<p>So the outcome of this policy is that it will apply an email address of <strong>alias@exchangeserverpro.net </strong>(because alias is used if nothing else is specified) to any recipient type.</p>
<h2>When are Exchange 2010 Email Address Policies Applied?</h2>
<p>But when does the email address policy apply? At the next dialog we can see the schedule options for the email address policy.</p>
<div id="attachment_4494" class="wp-caption aligncenter" style="width: 486px"><img class="size-full wp-image-4494" title="exchange-2010-email-address-policies-06" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-06.jpg" alt="Email address policy schedule options" width="476" height="216" /><p class="wp-caption-text">Email address policy schedule options</p></div>
<p>The options we can choose from are:</p>
<ul>
<li><strong>Do not apply</strong> &#8211; the email address policy will be created (or edited) but not applied to the recipients that fall within its scope</li>
<li><strong>Immediately</strong> &#8211; the email address policy will be applied immediately to the recipients that fall within its scope</li>
<li><strong>At the following time</strong> &#8211; the email address policy will be applied at the nominated time. This is convenient if you are preparing the email address policy in advance of a scheduled change (such as the rebranding exercise I mentioned earlier)</li>
</ul>
<p class="alert">Something you need to be aware of is that no matter which of the above options you pick <em>right now</em>, the email address policy will continue to be assessed and applied to recipients on an ongoing basis in the future each time a recipient is created or modified.</p>
<p>So for example when a new mailbox is created the email address policies are assessed and applied accordingly. Similarly, if you modify an existing mailbox user, for example to change their alias or move it to another database, the email address policies will be reassessed for that recipient.</p>
<p>For that reason you want to be sure that any email address policy that exists in your organization is ready to be applied to recipients.</p>
<h2>Creating a New Email Address Policy with the Exchange Management Console</h2>
<p>Click <strong>New E-Mail Address Policy</strong> to start creating a new policy.</p>
<div id="attachment_4496" class="wp-caption aligncenter" style="width: 318px"><img class="size-full wp-image-4496" title="exchange-2010-email-address-policies-07" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-07.jpg" alt="New Email Address Policy" width="308" height="203" /><p class="wp-caption-text">New Email Address Policy</p></div>
<p>For this example I&#8217;ve narrowed the scope of the email address policy to just one particular OU for &#8220;Example Corp&#8221;, the new business entity.</p>
<div id="attachment_4497" class="wp-caption aligncenter" style="width: 482px"><img class="size-full wp-image-4497" title="exchange-2010-email-address-policies-08" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-08.jpg" alt="Select recipient container for new email address policy" width="472" height="196" /><p class="wp-caption-text">Select recipient container for new email address policy</p></div>
<p>If that particular OU contained users in other companies I could also narrow the scope down based on Company or Department attributes, but in this example I don&#8217;t need to. Clicking <strong>Preview</strong> shows me the one user that exists in that OU so far.</p>
<div id="attachment_4498" class="wp-caption aligncenter" style="width: 557px"><img class="size-full wp-image-4498" title="exchange-2010-email-address-policies-09" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-09.jpg" alt="Email address policy conditions" width="547" height="287" /><p class="wp-caption-text">Email address policy conditions</p></div>
<p>Next I&#8217;ll add an SMTP address of <strong>%m@example.com</strong> to the policy (%m = &#8220;alias&#8221;).</p>
<div id="attachment_4499" class="wp-caption aligncenter" style="width: 495px"><img class="size-full wp-image-4499" title="exchange-2010-email-address-policies-10" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-10.jpg" alt="Configuring SMTP addresses for an email address policy" width="485" height="447" /><p class="wp-caption-text">Configuring SMTP addresses for an email address policy</p></div>
<p class="alert">Note that whatever domain you choose to use here needs to have already been configured as an <a href="http://technet.microsoft.com/en-us/library/bb124423.aspx">Accepted Domain</a> for the organization. If you haven&#8217;t already done so you can switch back to the Exchange Management Console and add the domain without having to cancel your new email address policy wizard.</p>
<p>Finally I will choose not to apply the email address policy just yet, so that I can demonstrate some scenarios for this.</p>
<div id="attachment_4500" class="wp-caption aligncenter" style="width: 479px"><img class="size-full wp-image-4500" title="exchange-2010-email-address-policies-11" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-11.jpg" alt="Choosing when to apply the email address policy" width="469" height="209" /><p class="wp-caption-text">Choosing when to apply the email address policy</p></div>
<p>Finally, click <strong>New</strong> to create the email address policy. If it all goes well you&#8217;ll see a successful completion message.</p>
<div id="attachment_4501" class="wp-caption aligncenter" style="width: 472px"><img class="size-full wp-image-4501" title="exchange-2010-email-address-policies-12" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-12.jpg" alt="Completing the new email address policy wizard" width="462" height="221" /><p class="wp-caption-text">Completing the new email address policy wizard</p></div>
<p>Note that the completion dialog reveals the <a href="http://exchangeserverpro.com/powershell">PowerShell</a> commands used behind the scenes to perform the task. This will be relevant later when we look at an example of creating an email address policy in PowerShell.</p>
<h2>Applying Email Address Policies</h2>
<p>Now let&#8217;s check the results. Because I chose not to apply the policy yet the user Amy Lawrence does not have an @example.com email address yet.</p>
<div id="attachment_4502" class="wp-caption aligncenter" style="width: 454px"><img class="size-full wp-image-4502" title="exchange-2010-email-address-policies-13" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-13.jpg" alt="Email addresses before the policy is applied" width="444" height="261" /><p class="wp-caption-text">Email addresses before the policy is applied</p></div>
<p>If I move another mailbox user into the same OU, they also do not have the email address policy applied.</p>
<div id="attachment_4504" class="wp-caption aligncenter" style="width: 485px"><img class="size-full wp-image-4504" title="exchange-2010-email-address-policies-14" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-14.jpg" alt="User moved into OU" width="475" height="229" /><p class="wp-caption-text">User moved into OU</p></div>
<p>Jo Rigby&#8217;s email addresses haven&#8217;t changed just because her OU membership changed.</p>
<div id="attachment_4505" class="wp-caption aligncenter" style="width: 414px"><img class="size-full wp-image-4505" title="exchange-2010-email-address-policies-15" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-15.jpg" alt="No change to email addresses yet" width="404" height="154" /><p class="wp-caption-text">No change to email addresses yet</p></div>
<p>However, if I modify Jo Rigby&#8217;s recipient properties, such as adding the new company name, and apply that change&#8230;</p>
<div id="attachment_4506" class="wp-caption aligncenter" style="width: 456px"><img class="size-full wp-image-4506" title="exchange-2010-email-address-policies-16" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-16.jpg" alt="Modifying recipient properties to trigger email address policies" width="446" height="243" /><p class="wp-caption-text">Modifying recipient properties to trigger email address policies</p></div>
<p>&#8230;the new SMTP address is immediately applied by the policy, because modifying and saving any change to a recipient triggers policy assessment.</p>
<div id="attachment_4507" class="wp-caption aligncenter" style="width: 418px"><img class="size-full wp-image-4507" title="exchange-2010-email-address-policies-17" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-17.jpg" alt="SMTP addresses after email address policy is applied" width="408" height="138" /><p class="wp-caption-text">SMTP addresses after email address policy is applied</p></div>
<p>If I simply wish to apply the email address policy to all of the users in that OU I can right-click the policy and choose <strong>Apply</strong>, and choose to apply it immediately or at a scheduled time.</p>
<div id="attachment_4508" class="wp-caption aligncenter" style="width: 519px"><img class="size-full wp-image-4508" title="exchange-2010-email-address-policies-18" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-18.jpg" alt="Manually applying an email address policy" width="509" height="148" /><p class="wp-caption-text">Manually applying an email address policy</p></div>
<p>Now Amy Lawrence also has the new @example.com email address without me having modified any of her other recipient properties, because I manually triggered the application of the policy.</p>
<div id="attachment_4509" class="wp-caption aligncenter" style="width: 419px"><img class="size-full wp-image-4509" title="exchange-2010-email-address-policies-20" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-20.jpg" alt="SMTP addresses after email address policy is applied" width="409" height="142" /><p class="wp-caption-text">SMTP addresses after email address policy is applied</p></div>
<p>You may wonder how primary SMTP address is determined when two policies are potentially valid for a recipient. The answer to that question is in the priority value of each policy. The policy with the highest priority will apply, but only that one policy applies.</p>
<p>For example, new user Bob Winder in the Example Corp OU gets mailbox-enabled and only receives an @example.com SMTP address from the &#8220;Example Corp&#8221; policy, but doesn&#8217;t receive an @exchangeserverpro.net address from the default policy that is of a lower priority.</p>
<div id="attachment_4513" class="wp-caption aligncenter" style="width: 419px"><img class="size-full wp-image-4513" title="exchange-2010-email-address-policies-24" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-24.jpg" alt="SMTP address for a new mailbox user" width="409" height="131" /><p class="wp-caption-text">SMTP address for a new mailbox user</p></div>
<p>So each policy needs to contain all of the SMTP addresses that you intend those recipients to receive, so that new recipients get them all. You can&#8217;t rely on different email address policies to apply cumulatively.</p>
<h2>Note: Email Address Policies are Additive Only</h2>
<p>You may have noticed in the examples above that the prior SMTP address of @exchangeserverpro.net was not removed from the mailboxes, it was simply changed to being a secondary email address.</p>
<p>This is due to the behavior of email address policies in that they are <em>additive only</em>. An email address policy will not remove or overwrite an email address on a recipient.</p>
<p>If the recipient falls out of scope of the email address policy they will not have any email addresses removed from the account, though their primary SMTP address may change when a different policy applies. In the case of Jo Rigby, if she is moved out of that OU and her company attribute changed again (or any other modification made to trigger policy assessment) she reverts to an @exchangeserverpro.net primary SMTP address, but retains @example.com as a secondary address.</p>
<div id="attachment_4510" class="wp-caption aligncenter" style="width: 414px"><img class="size-full wp-image-4510" title="exchange-2010-email-address-policies-21" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-21.jpg" alt="SMTP address changed after policy no longer applies" width="404" height="145" /><p class="wp-caption-text">SMTP address changed after policy no longer applies</p></div>
<p>Nor will the removal of the email address policy entirely cause recipients to lose those email addresses.</p>
<div id="attachment_4511" class="wp-caption aligncenter" style="width: 509px"><img class="size-full wp-image-4511" title="exchange-2010-email-address-policies-22" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-22.jpg" alt="Removing an email address policy" width="499" height="96" /><p class="wp-caption-text">Removing an email address policy</p></div>
<p>Note that removing a policy causes those recipients to assess policies again. Amy Lawrence&#8217;s primary SMTP address changed back to @exchangeserverpro.net with no other recipient modification or manual applying of other policies required, but again she retained the @example.com secondary address.</p>
<div id="attachment_4512" class="wp-caption aligncenter" style="width: 419px"><img class="size-full wp-image-4512" title="exchange-2010-email-address-policies-23" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-23.jpg" alt="SMTP addresses after email address policy is removed" width="409" height="140" /><p class="wp-caption-text">SMTP addresses after email address policy is removed</p></div>
<h2>Creating a New Email Address Policy with the Exchange Management Shell</h2>
<p>There will be times when you find the options available in the console when creating a new email address policy are not suitable for your particular scenario. In those cases you can use the Exchange Management Shell to create a more specific filter for the email address policy.</p>
<p>Email address policies are created using the <a href="http://technet.microsoft.com/en-us/library/aa996800.aspx">New-EmailAddressPolicy</a> cmdlet. This cmdlet has a <strong>-RecipientFilter</strong> parameter that <a href="http://technet.microsoft.com/library/bb738157(EXCHG.80).aspx">opens up a whole lot more possibilities</a> (the documentation refers to Exchange 2007 but is unchanged for Exchange 2010) for defining the scope of your email address policies. Just be aware that it can&#8217;t be used in combination with some other parameters, all of which is spelled out <a href="http://technet.microsoft.com/en-us/library/aa996800.aspx">here</a>.</p>
<p>So let&#8217;s look at one example of creating an email address policy in <a href="http://exchangeserverpro.com/powershell">PowerShell</a> using the capabilities of -RecipientFilter.</p>
<p>To begin with I&#8217;ve removed the policy I created in the console earlier, and manually removed the @example.com addresses from those mailboxes to start over with a clean slate.</p>
<div id="attachment_4515" class="wp-caption aligncenter" style="width: 552px"><img class="size-full wp-image-4515" title="exchange-2010-email-address-policies-25" src="http://exchangeserverpro.com/wp-content/uploads/2012/02/exchange-2010-email-address-policies-25.jpg" alt="Example Corp users in their OU" width="542" height="214" /><p class="wp-caption-text">Example Corp users in their OU</p></div>
<p>Now I&#8217;ll create the email address policy, using a recipient filter that checks display names for the string &#8220;(Example Corp)&#8221;. The new policy will have the following properties:</p>
<ul>
<li>A <strong>name</strong> of &#8220;Example Corp&#8221;</li>
<li>A <strong>priority</strong> of 1</li>
<li>An <strong>email address template</strong> of &#8220;SMTP:%m@example.com&#8221; (the upper-case SMTP defines the primary SMTP address, lower-case would be a secondary SMTP address)</li>
<li>A <strong>recipient filter</strong> for the DisplayName attribute of &#8220;*(Example Corp)&#8221; (the * is a wildcard)</li>
</ul>
<p>Running that as a command in the Exchange Management Shell looks like this:.</p>
<pre>New-EmailAddressPolicy -Name "Example Corp" -Priority 1 -EnabledEmailAddressTemplates "SMTP:%m@example.com" -RecipientFilter {DisplayName -like "*(Example Corp)"}

Name                                    Priority                                RecipientFilter
----                                    --------                                ---------------
Example Corp                            1                                       DisplayName -like '*(Example Corp)'</pre>
<p>Now the new email address policy has been created, but as before it has not yet applied to any recipients. To trigger the policy for the three Example Corp users I&#8217;m going to modify their display names to append &#8220;(Example Corp) to them. I&#8217;m just doing them individually here but you could script it if you had a lot of mailbox users to modify.</p>
<pre>[PS] C:\&gt;Set-Mailbox Jo.Rigby -DisplayName "Jo Rigby (Example Corp)"</pre>
<p>Jo now has the @example.com SMTP address assigned by the new policy.</p>
<pre>[PS] C:\&gt;Get-Mailbox Jo.Rigby | select displayname,emailaddresses | fl

DisplayName    : Jo Rigby (Example Corp)
EmailAddresses : {SMTP:Jo.Rigby@example.com, smtp:Jo.Rigby@exchangeserverpro.net}</pre>
<p>And if I change her display name so it no longer has &#8220;(Example Corp)&#8221; in it, she reverts to the primary SMTP address @exchangeserverpro.net and retains the @example.com as a secondary SMTP address.</p>
<pre>[PS] C:\&gt;Set-Mailbox Jo.Rigby -DisplayName "Jo Rigby"

[PS] C:\&gt;Get-Mailbox Jo.Rigby | select displayname,emailaddresses | fl

DisplayName    : Jo Rigby
EmailAddresses : {SMTP:Jo.Rigby@exchangeserverpro.net, smtp:Jo.Rigby@example.com}</pre>
<p>Hopefully this article has provided you a good understanding of how email address policies work in Exchange Server 2010, and given you some ideas on how you can use them in your own Exchange organization.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email" title="How to Set Up an Automated Exchange 2010 Database Backup Alert Email">How to Set Up an Automated Exchange 2010 Database Backup Alert Email</a></li><li><a href="http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility" title="Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange">Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell" title="Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell">Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell" title="Searching Exchange Server 2010 Message Tracking Logs with PowerShell">Searching Exchange Server 2010 Message Tracking Logs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/user-logged-mailbox-data-return" title="The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return">The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/exchange-server-2010-email-address-policies">Exchange Server 2010 Email Address Policies</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/exchange-server-2010-email-address-policies/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</title>
		<link>http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010</link>
		<comments>http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010#comments</comments>
		<pubDate>Mon, 06 Feb 2012 12:05:54 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Mailboxes]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Reporting]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4170</guid>
		<description><![CDATA[This PowerShell script produces a nicely formatted mailbox size report for Exchange Server 2010 or 2007]]></description>
			<content:encoded><![CDATA[<p>One of the <a href="http://exchangeserverpro.com">Exchange Server</a> administration tasks I perform almost every day is creating mailbox size reports. There are a few different reasons that I create these reports, such as planning a mailbox migration project, responding to a storage capacity alert for a particular database, or providing a specific team of people with a report of their mailbox sizes.</p>
<p>Now it is pretty easy to <a href="http://exchangeserverpro.com/browsing-mailbox-databases-in-exchange-2007-and-2010">get the sizes for Exchange mailboxes</a> and to handle the formatting of the<a href="http://exchangeserverpro.com/calculate-exchange-2010-mailbox-sizes-powershell"> Exchange 2010 mailbox statistics</a> so that they are easier to perform calculations on, but it gets a bit boring running those commands day after day.</p>
<p>Even worse, after running the commands to create a CSV report I still had to open that in Excel, remove the unwanted details, use Excel formulas to convert the values from bytes to megabytes, sort them into order, and so on. Again not difficult, just boring after doing it hundreds of times.</p>
<p>So I created a <a href="http://exchangeserverpro.com/tag/powershell">PowerShell</a> script, <strong>Get-MailboxReport.ps1</strong>, to do all of the heavy lifting for me, and I&#8217;m sharing that script with you here.</p>
<p class="alert"><strong>Download the script file here:</strong> <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Get-MailboxReport.zip" title="Version 1.1 downloaded 3603 times" >Get-MailboxReport.ps1</a> (downloaded 3603 times so far)</p>
<p>Let&#8217;s take a look at how the script works. Here if a video to demonstrate:<br />
<iframe src="http://www.youtube.com/embed/lEn6mjY4zws?rel=0" frameborder="0" width="600" height="437"></iframe></p>
<p>I&#8217;ve included help information within the script itself so you can use Get-Help to discover how to run the script.</p>
<pre>[PS] C:\Scripts\demo&gt;Get-Help .\Get-MailboxReport.ps1

NAME
    C:\Scripts\demo\Get-MailboxReport.ps1

SYNOPSIS
    Get-MailboxReport.ps1 - Mailbox report generation script.

SYNTAX
    C:\Scripts\demo\Get-MailboxReport.ps1 [-database ] []

    C:\Scripts\demo\Get-MailboxReport.ps1 [-file ] []

    C:\Scripts\demo\Get-MailboxReport.ps1 [-server ] []

    C:\Scripts\demo\Get-MailboxReport.ps1 [-mailbox ] []

    C:\Scripts\demo\Get-MailboxReport.ps1 [-all] []

DESCRIPTION
    Generates a report of useful information for
    the specified server, database, mailbox or list of mailboxes.
    Use only one parameter at a time depending on the scope of
    your mailbox report.

RELATED LINKS
    For more script details, a video demo, or to give feedback please go to:

http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010

REMARKS
    To see the examples, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -examples".
    For more information, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -detailed".
    For technical information, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -full".</pre>
<p>Depending on which parameter you use the output will vary.</p>
<ul>
<li>If you use the <strong>-mailbox</strong> parameter to query a single mailbox, then the output will appear in the console window. I don&#8217;t really see the need to output a single mailbox&#8217;s details to a CSV file.</li>
<li>If you use any of the other parameters, <strong>-server</strong>, <strong>-database</strong>, <strong>-file</strong>, or <strong>-all</strong>, the output will be written to a CSV file in the same folder you&#8217;re running the script from.</li>
<li>You can use the optional <strong>-filename</strong> parameter to specify your own output file name</li>
</ul>
<p>Once you&#8217;ve generated the CSV report you can open it with Excel and begin to analyze the data.</p>
<p class="alert"><strong>Download the script file here:</strong> <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Get-MailboxReport.zip" title="Version 1.1 downloaded 3603 times" >Get-MailboxReport.ps1</a> (downloaded 3603 times so far)</p>
<p>Change Log:</p>
<ul>
<li>6/02/2012 &#8211; V1.0 &#8211; Initial version</li>
<li>27/02/2012 &#8211; V1.1 - Improved recipient scope settings, exception handling, and custom file name parameter.</li>
</ul>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/move-exchange-mailboxes-text-file-powershell" title="How to Move Exchange Mailboxes in a Text File using PowerShell">How to Move Exchange Mailboxes in a Text File using PowerShell</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell" title="Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell">Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell" title="Searching Exchange Server 2010 Message Tracking Logs with PowerShell">Searching Exchange Server 2010 Message Tracking Logs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/user-logged-mailbox-data-return" title="The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return">The User Hasn&#8217;t Logged on to Mailbox So There is No Data to Return</a></li><li><a href="http://exchangeserverpro.com/test-mailflow-exchange-2003-servers" title="Using Test-Mailflow with Exchange 2003 Servers">Using Test-Mailflow with Exchange 2003 Servers</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010">Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</a> is © 2012 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010/feed</wfw:commentRss>
		<slash:comments>93</slash:comments>
		</item>
		<item>
		<title>Using Test-Mailflow with Exchange 2003 Servers</title>
		<link>http://exchangeserverpro.com/test-mailflow-exchange-2003-servers</link>
		<comments>http://exchangeserverpro.com/test-mailflow-exchange-2003-servers#comments</comments>
		<pubDate>Sun, 04 Dec 2011 12:32:49 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Exchange 2003]]></category>
		<category><![CDATA[Exchange 2007]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Test-Mailflow]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4300</guid>
		<description><![CDATA[How to use the Test-Mailflow cmdlet in Exchange 2007/2010 to verify mail flow for an Exchange 2003 server.]]></description>
			<content:encoded><![CDATA[<p>One of the challenges of managing a large <a href="http://exchangeserverpro.com">Exchange Server</a> environment is that you often need to support multiple versions of Exchange.</p>
<p>That means that often when you write a <a href="http://exchangeserverpro.com/tag/powershell">PowerShell</a> script you need to account for servers running different versions and adjust accordingly. It can turn a simple scripting exercise into a big task.</p>
<p>Recently I was looking at ways to include our Exchange 2003 servers in some monitoring scripts that are already running for Exchange 2007/2010 servers. I wanted to perform a mail flow test for the Exchange 2003 servers, because that is a test that (if successful) very quickly confirms a lot of the elements involved in email availability are in fact healthy (ie the server is up, reachable, accepting SMTP connections, processing mail queues, the Information Store is running, and more).</p>
<p>For Exchange 2007/2010 the <a href="http://technet.microsoft.com/en-us/library/aa995894.aspx">Test-Mailflow</a> cmdlet can be used for these. You can build it into a <a href="http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server">health check script</a> if you want to. But if you try to run it against an Exchange 2003 server you&#8217;ll get an error like this:</p>
<pre>
[PS] C:\&gt;Test-Mailflow -Identity EX2007SERVER -TargetMailboxServer EX2003SERVER

Test-Mailflow : "EX2003SERVER" is running a previous version of Exchange and does not support this task.
At line:1 char:14
+ Test-Mailflow &lt;&lt;&lt;&lt;  -Identity EX2007SERVER -TargetMailboxServer EX2003SERVER
    + CategoryInfo          : InvalidArgument: (:) [Test-Mailflow], OperationOnOldServerException
    + FullyQualifiedErrorId : 642F2C5C,Microsoft.Exchange.Monitoring.TestMailFlow</pre>
<p>However, if the Exchange 2003 server is in the same organization you can use a different parameter with Test-Mailflow to achieve the same result. All you need is an email address for one of the mailboxes on the Exchange 2003 server. You might want to create a mailbox on each of your Exchange 2003 servers (or even each of the databases on those servers) specifically for this purpose.</p>
<p>Then you simply run the Test-Mailflow cmdlet with the -TargetEmailAddress parameter instead of the -TargetMailboxServer parameter.</p>
<pre>[PS] C:\&gt;Test-Mailflow -Identity EX2007SERVER -TargetEmailAddress EX2003SERVER_test@domain.com

TestMailflowResult         MessageLatencyTime          IsRemoteTest
------------------         ------------------          ------------
Success                    00:00:19.5014893            True</pre>
<p>As you can see this is a nice, simple way to test your Exchange 2003 server health using PowerShell.</p>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/powershell-configuring-settings-multiple-exchange-mailbox-databases" title="PowerShell: Configuring Settings on Multiple Exchange Mailbox Databases">PowerShell: Configuring Settings on Multiple Exchange Mailbox Databases</a></li><li><a href="http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email" title="How to Set Up an Automated Exchange 2010 Database Backup Alert Email">How to Set Up an Automated Exchange 2010 Database Backup Alert Email</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-event-ids-powershell" title="Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell">Reporting Exchange Server 2010 Message Tracking Event IDs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/exchange-2010-message-tracking-log-search-powershell" title="Searching Exchange Server 2010 Message Tracking Logs with PowerShell">Searching Exchange Server 2010 Message Tracking Logs with PowerShell</a></li><li><a href="http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010" title="Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports">Get-MailboxReport.ps1 &#8211; PowerShell Script to Generate Mailbox Reports</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/test-mailflow-exchange-2003-servers">Using Test-Mailflow with Exchange 2003 Servers</a> is © 2011 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/test-mailflow-exchange-2003-servers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Health Check an Exchange 2010 Mailbox Server</title>
		<link>http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server</link>
		<comments>http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server#comments</comments>
		<pubDate>Mon, 21 Nov 2011 11:51:55 +0000</pubDate>
		<dc:creator>Paul Cunningham</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Exchange 2010]]></category>
		<category><![CDATA[Mailbox Server]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://exchangeserverpro.com/?p=4275</guid>
		<description><![CDATA[Get this free PowerShell script for performing a quick health check of your Exchange Server 2010 mailbox servers.]]></description>
			<content:encoded><![CDATA[<p>How many times each day do you get asked, <em>&#8220;Is there a problem with the Exchange server?</em>&#8221;</p>
<p>If you&#8217;re like me then you get asked this question at least once per day. Of course there usually isn&#8217;t anything wrong with our Exchange servers <img src='http://exchangeserverpro.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  but once the question has been asked then you have no choice but to investigate and confirm that everything is okay.</p>
<p>In this article I&#8217;m going to demonstrate how you can quickly check the health of your <a href="http://exchangeserverpro.com">Exchange Server 2010</a> mailbox servers, and share a script with you that can help to speed up this task.</p>
<p>Exchange Server 2010 has a series of PowerShell cmdlets that make it easy to do a health check of <a href="http://exchangeserverpro.com/exchange-2010-server-roles">mailbox servers</a>. For example, we can:</p>
<ul>
<li>Run <a href="http://exchangeserverpro.com/exchange-2010-test-servicehealth">Test-Servicehealth</a> to check the required services are all running</li>
<li>Run <a href="http://technet.microsoft.com/en-us/library/bb124924.aspx">Get-MailboxDatabase</a> to check whether the mailbox databases are mounted</li>
<li>Run <a href="http://technet.microsoft.com/en-us/library/bb123681.aspx">Test-MapiConnectivity</a> to verify that the databases are responding to MAPI requests</li>
<li>Run <a href="http://technet.microsoft.com/en-us/library/aa995894.aspx">Test-MailFlow</a> to confirm that email is able to pass successfully between two servers</li>
<li>Run <a href="http://technet.microsoft.com/en-us/library/dd298044.aspx">Get-MailboxDatabaseCopyStatus</a> for <a href="http://exchangeserverpro.com/exchange-server-2010-database-availability-group-installation-step-by-step">DAG</a> members to check the database copy status, queues, and content indexes</li>
</ul>
<p>That&#8217;s quite a few cmdlets to run, especially if we&#8217;ve got more than one mailbox server in the organization. And of course each of those cmdlets needs to run and show you output that you need to interpret.</p>
<p>I like to make life a bit easier and use PowerShell scripts to speed up these types of tasks. So naturally I put together a script for performing all of the above tests (and a few more) on my mailbox servers and display a nice simple colour-coded output so that I can tell at a glance whether there might be a problem.</p>
<p>This isn&#8217;t designed to do a diagnosis of any problems, it just checks the fundamentals and gives me a simple pass/fail and a few other indicators that I can then troubleshoot further if necessary.</p>
<p class="alert"><strong>Download the script file here:</strong> <a class="downloadlink" href="http://exchangeserverpro.com/wp-content/plugins/download-monitor/download.php?id=Test-MailboxServer.zip" title="Version 1.1 downloaded 1770 times" >Test-MailboxServer.ps1</a> (downloaded 1770 times so far)</p>
<p>Extract <strong>Test-MailboxServer.ps1</strong> from the Zip file and run it in your Exchange Management Shell to see output such as this:</p>
<p><img class="aligncenter size-full wp-image-4276" title="exchange-2010-test-mailboxserver-health-01" src="http://exchangeserverpro.com/wp-content/uploads/2011/11/exchange-2010-test-mailboxserver-health-01.jpg" alt="" width="580" height="446" /></p>
<p>If you have any questions or bugs to report please let me know in the comments below.</p>
<p><strong>Change log:</strong></p>
<ul>
<li>V1.0, 20/11/2011 &#8211; Initial version</li>
<li>V1.1, 10/01/2011 &#8211; Fixed $null&#8217;s, bugs with Recovery DBs, and ping failure scenarios</li>
</ul>
<h3  class="related_post_title">Related posts:</h3><ul class="related_post"><li><a href="http://exchangeserverpro.com/powershell-script-check-exchange-mailbox-database-backup-time" title="PowerShell Script: Check Exchange Mailbox Database Last Backup Time">PowerShell Script: Check Exchange Mailbox Database Last Backup Time</a></li><li><a href="http://exchangeserverpro.com/set-automated-exchange-2010-database-backup-alert-email" title="How to Set Up an Automated Exchange 2010 Database Backup Alert Email">How to Set Up an Automated Exchange 2010 Database Backup Alert Email</a></li><li><a href="http://exchangeserverpro.com/exchange-server-update-rollups-forefront-fscutility" title="Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange">Dealing with Exchange Server Update Rollups and Forefront Protection for Exchange</a></li><li><a href="http://exchangeserverpro.com/test-lab-email-traffic-generator-powershell-script" title="PowerShell Script to Generate Email Traffic in a Test Lab Environment">PowerShell Script to Generate Email Traffic in a Test Lab Environment</a></li><li><a href="http://exchangeserverpro.com/list-users-access-exchange-mailboxes" title="How to List all Users Who Have Access to Other Exchange Mailboxes">How to List all Users Who Have Access to Other Exchange Mailboxes</a></li></ul><hr />
<p>This article <a href="http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server">How to Health Check an Exchange 2010 Mailbox Server</a> is © 2011 ExchangeServerPro.com</p>
<p>Get more <a href="http://exchangeserverpro.com">Exchange Server tips</a> at <a href="http://exchangeserverpro.com">ExchangeServerPro.com</a></p>]]></content:encoded>
			<wfw:commentRss>http://exchangeserverpro.com/health-check-exchange-2010-mailbox-server/feed</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
	</channel>
</rss>

