A Script To Send Mailbox Quotas To All Your Exchange Mailbox Users.

Leave a comment
Share

Here’s a little powershell script that will send an email to all your Exchange Server mailbox users, that will tell them the current size of their mailbox, and the applicable mailbox quotas. Save the text into a .ps1 file, using Notepad (you can call it whatever you like - something like emailquotas.ps1). To run it, open an Exchange Management Shell window, and type in the path and file name. If it is in the root of your server C: drive, you might type in .\emailquotas.ps1 .

Note that as it stands, the script will only check (and send an email to) the Administrator mailbox – this is so that you can test it without sending loads of email messages out. When you are ready to run it for real, change the line that says

$Mailboxes = Get-Mailbox Administrator

to say simply

$Mailboxes = Get-Mailbox -ResultSize Unlimited

I’d advise you to do it when things are quiet – if you have a lot of users, it will keep your server quite busy for a while. Please note that where you see things like “yourdomain.com”, “YourAdminPassword”, “administrator@yourdomain.com”, you will of course need to supply your own values. And if you’re actually going to use your administrator account and password for this (BTW, you don’t really need to), PLEASE DON’T LEAVE THE SCRIPT WHERE EVERYONE CAN SEE IT.

$numDbs = 0
$servers = @()
$dbIdentities = @()
$issueWarningQuotas = @()
$prohibitSendQuotas = @()
$prohibitSendReceiveQuotas = @()
Get-MailboxDatabase | foreach {
  $numDbs = $numDbs + 1
  $servers = $servers + $_.Server
  $dbIdentities = $dbIdentities + $_.Identity
  $issueWarningQuotas = $issueWarningQuotas + $_.IssueWarningQuota
  $prohibitSendQuotas = $prohibitSendQuotas + $_.ProhibitSendQuota
  $prohibitSendReceiveQuotas = $prohibitSendReceiveQuotas + $_.ProhibitSendReceiveQuota
}
for ($i = 0; $i -lt $numDbs; $i++)
{
  write-host “Server:” $Servers[$i]
  write-host “Database:” $dbIdentities[$i]
  write-host “Issue Warning Quota:” $issueWarningQuotas[$i]
  write-host “Prohibit Send Quota:” $prohibitSendQuotas[$i]
  write-host “Prohibit Send/Receive:” $prohibitSendReceiveQuotas[$i]
}
$Mailboxes = Get-Mailbox Administrator
$Mailboxes | foreach {
  $_.DisplayName
  $serverName = $_.ServerName
  $dbName = $_.Database
  if ($_.UseDatabaseQuotaDefaults)
  {
    for ($i = 0; $i -lt $numDbs; $i++)
    {
      if (($serverName -eq $Servers[$i]) -and ($dbName -eq $dbIdentities[$i]))
      {
        $issueWarningQuota = $issueWarningQuotas[$i]
        $prohibitSendQuota = $prohibitSendQuotas[$i]
        $prohibitSendReceiveQuota = $prohibitSendReceiveQuotas[$i]
        break
      }
    }
  }
  else
  {
    $issueWarningQuota = $_.IssueWarningQuota
    $prohibitSendQuota = $_.ProhibitSendQuota
    $prohibitSendReceiveQuota = $_.ProhibitSendReceiveQuota
  }
  $Statistics = Get-MailboxStatistics $_
  $msgBody = “<body style=`”font-family:Sans-serif;`”>” +
    “<p>Mailbox statistics for ” + $_.DisplayName + “</p>” +
    “<p><table style=`”font-family:Sans-serif;`”>” +
    “<tr><td>Total Item Size: </td><td>” + $Statistics.TotalItemSize + “</td></tr>” +
    “<tr><td>Storage Limit Status: </td><td>” + $Statistics.StorageLimitStatus + “</td></tr>” +
    “<tr><td>Issue Warning Quota: </td><td>” + $issueWarningQuota + “</td></tr>” +
    “<tr><td>Prohibit Send Quota: </td><td>” + $prohibitSendQuota + “</td></tr>” +
    “<tr><td>Prohibit Send/Receive: </td><td>” + $prohibitSendReceiveQuota + “</td></tr>” +
    “</table></p></body>”
  $email = New-Object System.Net.Mail.MailMessage
  $email.IsBodyHtml = $true
  $email.From = New-Object System.Net.Mail.MailAddress(“administrator@yourdomain.com”)
  $email.To.Add($_.primarySmtpAddress.ToString())
  $email.Subject = “Mailbox statistics”
  $email.Body = $msgBody
  $smtp = New-Object System.Net.Mail.SmtpClient(“yourdomain.com”)
  $smtp.Credentials = New-Object System.Net.NetworkCredential(“Administrator”, “YourAdminPassword”)
  $smtp.Send($email)
}





Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>