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 {

param(

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

[String]$File,

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

[ValidateRange(1, 5120)]

[UInt16]$MegaByte = 1,

[Switch]$ShowProgress

)

# 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 =

'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789-_'

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

$sw.Write($str_)

# show progress

if ($ShowProgress) {

$strings++

$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_

}

}

$sw.Close()

$sw.Dispose()

# release resources through garbage collection

[GC]::Collect()

}

 

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

Comments are closed.