All what’s inside * * should be edited
If ((Get-PSSnapin | where {$_.Name -match “Exchange.Management”}) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
$toArray=Get-Mailboxdatabase *databasename* | Get-Mailbox | foreach-object {$email = $_.primarysmtpaddress; $_ | Get-MailboxStatistics | Where {$_.TotalItemSize.Value.ToMB() -gt 512 } | select @{ expression={$email}}}
$from= “*Administartor@domain.com*”
Foreach ($to in $toArray)
{
$s=[string]$to
[int]$Start = $s.IndexOf(“=”)
[int]$End = $s.IndexOf(“}”)
[string]$ss=$s.Substring($Start+1,$End-$start-1)
$Statistics = Get-MailboxStatistics $ss
$name = Get-Mailbox $ss
$messageParameters = @{
smtpServer = “*ExchangeCASHUBserver*”
From = [string]$from
To = $ss
Subject = “Warning!”
Body = “Hi “+ $name + “.Your mailbox size is ” + $Statistics.TotalItemSize + ” Your mailbox size limit is 500 MB. Please delete unnecessary emails to reduce size of your mailbox ”
}
Send-MailMessage @messageParameters -BodyAsHtml
}