PS Module – Fill up Mailboxes

Send-PileMail, a PowerShell Module written to automaticly send emails to a set of Mailboxes, with the purpose to test migration throttling.

We can look at Microsoft Technet Article on Exchange Online Migration Performance and Best Practice, but it doesn’t give us the numbers in order to calculate the amount of time we need to Schedule migration process. There is an Excel Spreadsheet to help out abit, but still it doesn’t give us the hard facts.

So this Script fills up all the mailboxes we input with SamAccountName, by sending them X count of emails with an attachment. I used a txt file at 96mb, created with Wordpad, by just copying text and saved the file several times until the file reached 96mb.

Command Prompt/PowerShell v3.0
ActiveDirectory PowerShell Cmdlets. Can be installed With PowerShell: Install-WindowsFeature RSAT-AD-PowerShell

Feel free to use and contribute to the Script With Git:

Or just copy the script from here:

#Author: Roy Apalnes
#Author Mail:
#Author Twitter: @royapalnes
#Author Blog:
#Contributor: Simon Wåhlin, Christian Knarvik

Function Send-PileMail

        [ValidateScript({Test-Path $_})]
        #Commands we run one time
        ForEach ($Name in $SamAccountName)
            #Commands we run once per user
            $ADUser = Get-ADUser -Filter {samAccountName -eq $Name} -Property mail
                $mail = $ADUser.Mail
                    # Commands we run $Count times per user
                    Write-Progress -Activity ('Processing user: {0}' -f $ADUser.sAMAccountName) -Id 1 -PercentComplete ($i/$Count*100)
                    Send-MailMessage -SmtpServer $SmtpServer -To $mail -From $From -Subject "Piling up Mail #$i" -Body 'MyBody' -Attachments $file
                Write-Progress -Activity ('Processing user: {0}' -f $ADUser.sAMAccountName) -Id 1 -Completed
                Write-Warning -Message ('User: [{0}] does not have email populated.' -f $ADUser.sAMAccountName)
        #Commands we run when Script is ending

# Pre-set Variables:
# 'user1','user2','user3' | Send-PileMail -Path 'D:\Temp\File.txt' -SmtpServer '' -From '' -Count 330

# Asks for Variables:
# Send-PileMail

Big thanks to Simon @

Leave a Reply


I am Roy Apalnes, a Microsoft Cloud Evangelist working av Sopra Steria. Main focus in Microsoft Security and Endpoint Management, with a bigger picture in mind.

Featured Posts