Fattening up an Exchange mailbox

Sometimes when doing mailbox testing it's necessary to actually bloat a mailbox for the purposes of benchmarking the speed of a mailbox move to Office 365, rather than risk sending sensitive data, or wasting time trying to wrangle up enough PDF or other files, you can use the following PowerShell function and one-liner to create random files and send them to the mailbox in question.


First you'll want to either add the following function to your PowerShell profile, or dot-source it so you can use it by your one-liner.


Function New-BigRandomFile {


[Parameter(Mandatory = $true, Position = 0)]


[Parameter(Mandatory = $false, Position = 1)]

[ValidateRange(1, 5120)]

[UInt16]$MegaByte = 1,



# get/create the file's full path

$path = if (Test-Path $File -PathType Leaf) {

Resolve-Path $File

} else {

Join-Path $pwd $File


$total = 1mb * $MegaByte

$strings = $bytes = 0

# create the stream writer

$sw = New-Object IO.streamWriter $path

# get a 64 element Char[]; I added the – and _ to have 64 chars

[char[]]$chars =


1..$MegaByte | ForEach-Object {

# get 1MB of chars from 4 256KB strings

1..4 | ForEach-Object {

# randomize all chars and…

$rndChars = $chars | Get-Random -Count $chars.Count

# …join them in a string

$str = -join $rndChars

# repeat random string 4096 times to get a 256KB string

$str_ = $str * 4kb

# write 256KB string to file


# show progress

if ($ShowProgress) {


$bytes += $str_.Length

Write-Progress -Activity "Writing String #$strings" `

-Status "$bytes Bytes written" `

-PercentComplete ($bytes / $total * 100)


# release resources by clearing string variables

Clear-Variable str, str_





# release resources through garbage collection




Next, you'll want to set a variable, we'll use $count, to 1

$count = 1


Now we'll just loop 25 times and send a 50Mb file each time.  (Change the highlighted text to alter this behavior)

while ($count -le 25){New-BigRandomFile "test$count.txt" 50;Send-MailMessage -Subject "Test email $count" -Attachments "test$count.txt" -To smtpAddressOfMailbox -SmtpServer yourSmtpServerNameOrIpHere -Body "Test email number $count";$count++}

Obviously you'll want to change the SMTPServer name and email address of the test mailbox.

I take no credit, BTW, for the New-BigRandomFile function, I found it some time ago and it's part of my normal profile so I thought I'd just include it here.

 ** As always, use this at your own risk.   Test Test Test, and make sure you've got a good backup and know how to restore it. ***



Reader Comments

Leave a Reply

Your email address will not be published. Required fields are marked *