I’ve been looking around for some good ways to flesh out an Exchange lab to test some migration scenarios. I’ve gotten a lot of good advice from people on good ways to do this, but I really wanted something simple and elegant. Here’s what I settled on:
The Concept
Ed Crowley, MVP and all-around good guy (I suspect, since I’ve never actually met the guy), suggested that I just simply use a script to build a bunch of RFC-822 formatted files with the *.eml extension and then dump them in the Transport folder. This will cause Exchange 2007 to look at them and deliver them to the mailbox that they need to go to. I remember using some hackery like this back when I was manually looking at spam on an Exchange 2003 box. I would gather up all the false positives and resubmit them to the dumpster for delivery. The real benefit of this method is that I can use PowerShell to generate those files a LOT more quickly than I can figure out a script to generate the actual SMTP submission.
The Script
Once I did the research on what the RFC-822 format actually requires, here’s the PowerShell script I wrote to generate mail messages for the three test mailboxes:
<#
This is a script to generat a bunch of *.eml files and dump them in the transport directory of Exchange
Tim Robichaux
1/14/2010
EMLGenerationScript.ps1
#>
$Users = @();
$Users = "TimTest1","TimTest2","TimTest3";
$Body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam id mauris sit amet nisl <snip> rutrum tempus, enim nisi sed.";
foreach ($User in $Users) {
$Counter = 1;
While ($Counter -lt 100){
$To = "To: " + $User + "@testdomain.com";
$From = "From: " + "tim@testdomain.com";
$Subject = "Subject: " + "This is test message `#$Counter";
$GUID = [system.guid]::newguid();
echo $From $To $Subject "`n" $Body | out-file "C:\Program Files\Microsoft\Exchange Server\TransportRoles\Pickup\$GUID.eml" -Encoding ASCII;
$Counter += 1;
}
}
The Outcome
It looks like the server that I’m populating is a VM, so I’ve totally swamped the transport service as it’s taking quite a while to deliver the messages. Another interesting thing is that it looks like it’s delivering them based on the order of the GUID, rather than the timestamp, so they’re showing up in all sorts of odd order.
I have to label this project as a success so far. I wanted to be able to generate some content quickly and I have to say that the hour I’ve spent getting this straight was worth it, balanced on the time it would have taken to populate messages by hand.
Lessons Learned and Future Revisions
There are a couple of really important things I learned from this. First off, the cmdlet “out-file” defaults to the system default. This means that if you are using it for generating some raw text, you have to explicitly set “ASCII” or whatever you need. I’ve run into this gottcha before, but it’s no less frustrating. Another thing that I learned from this is that older versions of PowerShell don’t always like comments and things like that. It’s often quite confusing about what you can do on a given system with the version of PowerShell that’s installed.
In future revisions, I want to build this into a user account generation script so that at the time of generation, I create the user, generate the mailbox and then populate it. Another thing that I would like to do is set up an array or pool of “From” addresses to give a little bit variety. Also a nice feature would be to add a “-FromFile” switch that would allow me to populate a bunch of the variables from a config file.