PoshCode Logo PowerShell Code Repository

Exch07 Quota Report by GEOINFO 17 months ago
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2117"></script>download | new post

Power Shell 1 script used to grab mailbox stats for a Exchange 2007 server. It saves the information into a .csv file by changing the $OUTFILE variable.

The script is pretty basic but it’s a simple way of having a history of how people use their inbox space. There is no method for managing the saved files. I just make it a point to delete them when I run my months end maintenance.

  1. #Get information on everybodies inbox and spit it out with total sizes #in MB.  Sorts the list by StorageLimitStatus
  2. #NOTE THAT I HAD TO USE ASCII WITH OUT-FILE AS NO OTHER ENCODING WOULD #PROPERLY IMPORT CSV INTO EXCEL
  3.  
  4. #create a date var to stick in the filename
  5. $date = get-date -Format MM-dd-yyyy
  6.  
  7. #create a outfile var so we only have to update it in one spot
  8. $OUTFILE = "C:\Net_Admin_Stuff\usage_reports\daily_storage_limits\Daily_Storage_Limits-$date.csv"
  9.  
  10. #Create the default db send/receive quota divided by 1024 to convert KB to MB.
  11. $DEFAULTSENDQUOTA = 510000/1024
  12.  
  13. #Create a header to display at the top.
  14. $HEADER = "Display Name,Storage Limit Status,Item Count,Total Item Size (MB),Deleted Item Count,Total Deleted Item Size (MB),Prohibit Send/Receive Quota (MB),Quota Source"
  15. $HEADER | Out-File $OUTFILE -Append -Encoding Ascii
  16.  
  17. #Get mailbox stats for all users, sort by Storage Limit Status and go through each users objects
  18. Get-MailboxStatistics |  where {$_.ObjectClass -eq 'Mailbox'} | Sort-Object StorageLimitStatus | ForEach-Object {              
  19.         #Get the current user so we can grab some information from the get-mailbox command     
  20.         $CURUSER = get-mailbox -Identity $_.Identity  
  21.  
  22.         #if the current user is using db defaults it will show a value of unlimited, which can't be calculated.    
  23.         #Push the default value into the field when this happens  
  24.         #Label where the source of the quota came from 
  25.         If ($CURUSER.UseDatabaseQuotaDefaults -eq $true)
  26.         {
  27.                 $QUOTASRC = $CURUSER.Database    
  28.                 $SENDQUOTA = $DEFAULTSENDQUOTA 
  29.         }  
  30.         else  
  31.         {    
  32.                 $QUOTASRC = "User Profile"    
  33.                 $SENDQUOTA = $CURUSER.ProhibitSendReceiveQuota.Value.ToMB()      
  34.         }      
  35.  
  36.         #Generate useable vars for each of the objects that we're going to work with.  
  37.         $DNAME = $_.DisplayName;       
  38.         $SLSTATUS = $_.StorageLimitStatus;     
  39.         $ICOUNT = $_.ItemCount;
  40.         $TISIZE = $_.TotalItemSize.Value.ToMB();       
  41.         $DICOUNT = $_.DeletedItemCount;
  42.         $TDISIZE = $_.TotalDeletedItemSize.Value.ToMB();       
  43.  
  44.         #spit out our information into a single row    
  45.         "$DNAME,$SLSTATUS,$ICOUNT,$TISIZE,$DICOUNT,$TDISIZE,$SENDQUOTA,$QUOTASRC"
  46. } | Out-File $OUTFILE -Append -Encoding Ascii

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me