Just a quick but helpful script today for generating mailbox test data. While there are other scripts available that can send test emails to populate a mailbox, in some instances you need those emails to be spread out over a span of time.
If you want to test out archiving, retention policies, OST caching or any other date-sensitive operation, a mailbox full of test data from the day prior is not that helpful.
In the script below, you can populate a test mailbox with emails going back X number of days with Y number of emails per day.
Some of the code in this script was inspired by examples from Glen Scales and Mike Pfeiffer. Glen is pretty well known as the go-to for all things EWS API related and Mike has a nice script for generating lab mailboxes.
This script uses version 2.2 of the EWS Managed API. If you don’t have it installed, you can download it from Microsoft: Microsoft Exchange Web Services Managed API 2.2. The API should install in a default folder of “C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll”, if you install it in a different location you will want to modify the script or use the command line parameter to specify the alternate location.
You will also need an account that is setup for Impersonation. If you don’t have an account with this role, you can easily set it up with these instructions: “How To: Configure Impersonation“.
Using The Script
The script takes up to eight command line switches although you can specify as few as one. The parameters are as follows:
The SMTP address for the mailbox that you want to populate.
The number of days back from the current date to start populating messages. Default value is 120 days.
The number of messages to create for each day. Default value is 5 messages per day.
The size of the attachment for the message. Default value is 100kb.
If specified as $True, Autodiscover is used to determine the EWS endpoint. Default value is $True.
EWS endpoint for target mailbox. Default value is to use Office 365 if not using Autodiscover.
Location of EWS API. Default path is “C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll”.
Exchange version to be used by EWS. Default is “Exchange2013_SP1” and likely does not need to be changed unless you’re using an earlier version of Exchange. Acceptable options are documented at “EWS schema versions in Exchange“.
So using the following would give us a mailbox with 3 years of email where there are 10 messages per day of 200 KB each:
.\Populate-TestMailbox.ps1 -TargetMailbox email@example.com -NumDaysBack 1095 -MsgsPerDay 10 -MsgSize 200kb
When executing the script, you’ll be prompted for the credentials of the account that has the Impersonation role.
It should be noted that this script does not actually “send” emails as you cannot send the email and fake the date; instead, it creates emails and saves them into the Inbox folder. I have not noticed any difference in the operation of functions like retention policies or OST caching but it’s something to watch for.
The script for this post can be found in the Microsoft Script Center at the following link: Populate-TestMaiboxByDate.ps1
Did you find this article helpful?
Leave a comment below or follow me on Twitter (@JoePalarchio) for additional posts and information on Office 365.
Looking to do some more reading on Office 365?
Catch up on my past articles here: Joe Palarchio.