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.

Requirements:
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: https://github.com/RoyApalnes/Microsoft/blob/master/Send-PileMail.psm1

Or just copy the script from here:

#Author: Roy Apalnes
#Author Mail: roy.apalnes@gmail.com
#Author Twitter: @royapalnes
#Author Blog: johana30.sg-host.com
#Contributor: Simon Wåhlin, Christian Knarvik

Function Send-PileMail
{
    [cmdletbinding()]
    Param
    (
        [Parameter(Mandatory,ValueFromPipeline)]
        [String[]]
        $SamAccountName,

        [Parameter(Mandatory,ValueFromPipelineByPropertyName)]
        [ValidateScript({Test-Path $_})]
        [String]
        $Path,
        
        [Parameter(Mandatory,ValueFromPipelineByPropertyName)]
        [String]
        $SmtpServer,
        
        [Parameter(Mandatory,ValueFromPipelineByPropertyName)]
        [String]
        $From,
        
        [Parameter(Mandatory,ValueFromPipelineByPropertyName)]
        [Int]
        $Count
    )
    Begin
    {
        #Commands we run one time
    }
    Process
    {
        ForEach ($Name in $SamAccountName)
        {
            #Commands we run once per user
            $ADUser = Get-ADUser -Filter {samAccountName -eq $Name} -Property mail
            if(-Not([String]::IsNullOrEmpty($ADUser.Mail)))
            {
                $mail = $ADUser.Mail
                for($i=1;$i-le$Count;$i++)
                {
                    # 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
            }
            else
            {
                Write-Warning -Message ('User: [{0}] does not have email populated.' -f $ADUser.sAMAccountName)
            }
        }
    }
    End
    {
        #Commands we run when Script is ending
    }
} 

# Pre-set Variables:
# 'user1','user2','user3' | Send-PileMail -Path 'D:\Temp\File.txt' -SmtpServer '192.168.0.10' -From 'roy.apalnes@johana30.sg-host.com' -Count 330

# Asks for Variables:
# Send-PileMail

Big thanks to Simon @ http://blog.simonw.se/


Leave a Reply

Ehlo!

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