Wednesday, April 16, 2014

Quota if Mailbox Size script for Exchange 2010,2013

If your playing around with different Mailbox quota values you might want to see what the usage of those quotas would be before you apply them to a Mailbox. This is a very simple Mailbox Size script for Remote Powershell to show you this with a funky console graph output (and a CSV report) eg


So what the script does is the normal Get-Mailbox | Get-MailboxStatistics to get the TotalSize of the Mailbox in MB and compares that against a QuotaIf Value you feed into script in the above example that was 2000 MB. It then works out the current percentage used and the produces an Alt-ASCII graph and the above table.

When you run this script you need to feed in the QuotaIf value eg

.\quotaIf.ps1 2000

I've put a download of this script here and code itself looks like

  1. $QuotaIfVal = $args[0]  
  2. $Script:rptCollection = @()  
  3. get-mailbox -ResultSize unlimited| Get-MailboxStatistics | foreach-object{  
  4.     $rptObj = "" | Select MailboxName,TotalSize,QuotaIfPercent,PercentGraph  
  5.     $rptObj.MailboxName = $_.DisplayName  
  6.     [Int64]$rptObj.TotalSize = ($_.TotalItemSize.ToString() |%{($_.Substring($_.indexof("(")+1,$_.indexof("b")-$_.indexof("(")-2)) -replace(",","")})/1MB  
  7.   
  8.     $rptObj.QuotaIfPercent = 0    
  9.     if($rptObj.TotalSize -gt 0){  
  10.         $rptObj.QuotaIfPercent = [Math]::round((($rptObj.TotalSize/$QuotaIfVal) * 100))   
  11.     }  
  12.     $PercentGraph = ""  
  13.     for($intval=0;$intval -lt 100;$intval+=4){  
  14.         if($rptObj.QuotaIfPercent -gt $intval){  
  15.             $PercentGraph += "▓"  
  16.         }  
  17.         else{         
  18.             $PercentGraph += "░"  
  19.         }  
  20.     }  
  21.     $rptObj.PercentGraph = $PercentGraph   
  22.     $rptObj | fl  
  23.     $Script:rptCollection +=$rptObj   
  24. }  
  25. $Script:rptCollection  
  26. $Script:rptCollection | Export-Csv -NoTypeInformation -Path c:\temp\QuotaIfReport.csv -Encoding UTF8