Skip to main content

Version 5 of the Mailbox Size Gui Script for Exchange 2007

***** If your running Exchange 2010 please see http://gsexdev.blogspot.com/2010/03/mailbox-size-gui-exchange-2010-remote.html ********

Okay time for a new version of the mailbox size gui the last version had a number of large bugs and the quota code looked like it had been written by a drunk squirrel. So this version firstly fixes the bugs in the quota code and the bugs with Deleted items sizes and adds some new functionality.

The first addition is a drop down box that allows selection of which quota value you want to report on Eg exchange offers 3 quota levels Warning, Prohibit Send and Prohibit Send and Receive so the script will now allow reporting on which ever Quota usage you want to look at. This section still needs a little work to get better performance as it re-queries the server for mailbox sizes when you change the quota dropdown box instead of just reusing the current result.

The second and most exciting feature is the mailbox size growth feature this is the biggest change and requires some explanation.

Firstly when the script runs now it will create a folder on the c drive called mbsizehistory, it will then record the results of each mailbox size query you make to a csv file in this directory with a serial date as the file name along with the servername . It will only create one file per day and per server you run it against.

So basically every time you run this script it will create this file so if you run it once a week or one a day or every three days you will start collecting adhoc history data about your mailbox size growth. Convention wisdom and what I’ve done in the past is record this type of data to a database every day and then build table, view and graph report on this data. While this is possible with the script the amount of complexity of setup and other backend you need starts getting beyond the technology that might be generally available for a simple script like this. But this where the cool and exciting part comes in to cater for this and allow aggregation of random history files using a few simple date algorithms, hash table and loops I’ve come up with a serial date, random file aggregation datatable. This part is highly experimental as it was only written last week so I haven’t tested it with real data only mock data and haven’t tested it with multiple servers so going on past experience the squirrel may make another appearance. But with the limited testing I’ve done it does work and I think its pretty cool and useful. Basically it aggregates the previous result from the files and tries to show the mailbox growth over 1 day,7days,1 month and 1 year. Because the dates of the file may be intermediate the script handles getting the file that is as closest to the growth date's as possible.

I’ve put a downloadable of the new version here the growth section looks like

function ShowGrowth(){


$gtTable.clear()
$datetime = get-date
$arArrayList = New-Object System.Collections.ArrayList
dir c:\mbsizehistory\*.csv | foreach-object{
$fname = $_.name
$nmArray = $_.name.split("-")
if ($nmArray[1].Replace(".csv","") -eq $snServerNameDrop.SelectedItem.ToString()) {
[VOID]$arArrayList.Add($nmArray[0])
}
}
$arArrayList.Sort()
$spoint = $arArrayList[$arArrayList.Count-1]
$oneday = $spoint
$sevenday = $spoint
$onemonth = $spoint
$oneyear = $spoint
foreach ($file in $arArrayList){
if ($file -gt ($datetime.Adddays(-2).ToString("yyyyMMdd")) -band $file -lt $oneday) {$oneday = $file}
if ($file -gt ($datetime.Adddays(-7).ToString("yyyyMMdd")) -band $file -lt $sevenday) {$sevenday = $file}
if ($file -gt ($datetime.Adddays(-31).ToString("yyyyMMdd")) -band $file -lt $onemonth) {$onemonth = $file}
if ($file -gt ($datetime.Adddays(-256).ToString("yyyyMMdd")) -band $file -lt $oneyear) {$oneyear = $file}
}
write-host $oneday
write-host $sevenday
write-host $onemonth
write-host $oneyear

$onedaystats = @{ }
$sevendaystats = @{ }
$onemonthsdaystats = @{ }
$oneyearstats = @{ }

Import-Csv ("c:\mbsizehistory\" + $oneday + "-" + $snServerNameDrop.SelectedItem.ToString() + ".csv") | %{
$onedaystats.add($_.DisplayName,$_.TotalItemSize)
}
Import-Csv ("c:\mbsizehistory\" + $sevenday + "-" + $snServerNameDrop.SelectedItem.ToString() + ".csv") | %{
$sevendaystats.add($_.DisplayName,$_.TotalItemSize)
}
Import-Csv ("c:\mbsizehistory\" + $onemonth + "-" + $snServerNameDrop.SelectedItem.ToString() + ".csv") | %{
$onemonthsdaystats.add($_.DisplayName,$_.TotalItemSize)
}
Import-Csv ("c:\mbsizehistory\" + $oneyear + "-" + $snServerNameDrop.SelectedItem.ToString() + ".csv") | %{
$oneyearstats.add($_.DisplayName,$_.TotalItemSize)
}

foreach($row in $msTable.Rows){
if ($onedaystats.ContainsKey($row[0].ToString())){
$ondaysizegrowth = $row[2] - $onedaystats[$row[0].ToString()]
}
else{$ondaysizegrowth = 0}
if ($sevendaystats.ContainsKey($row[0].ToString())){
$sevendaysizegrowth = $row[2] - $sevendaystats[$row[0].ToString()]}
else{$sevendaysizegrowth = 0}
if ($onemonthsdaystats.ContainsKey($row[0].ToString())){
$onemonthsizegrowth = $row[2] - $onemonthsdaystats[$row[0].ToString()]}
else{$onemonthsizegrowth = 0}
if ($oneyearstats.ContainsKey($row[0].ToString())){
$oneyearsizegrowth = $row[2] - $oneyearstats[$row[0].ToString()]}
else{$oneyearsizegrowth = 0}
$gtTable.rows.add($row[0].ToString(),$row[2],$ondaysizegrowth,$sevendaysizegrowth,$onemonthsizegrowth,$oneyearsizegrowth)

}
$dgDataGrid.DataSource = $gtTable

}


Popular posts from this blog

Testing and Sending email via SMTP using Opportunistic TLS and oAuth in Office365 with PowerShell

As well as EWS and Remote PowerShell (RPS) other mail protocols POP3, IMAP and SMTP have had OAuth authentication enabled in Exchange Online (Official announcement here ). A while ago I created  this script that used Opportunistic TLS to perform a Telnet style test against a SMTP server using SMTP AUTH. Now that oAuth authentication has been enabled in office365 I've updated this script to be able to use oAuth instead of SMTP Auth to test against Office365. I've also included a function to actually send a Message. Token Acquisition  To Send a Mail using oAuth you first need to get an Access token from Azure AD there are plenty of ways of doing this in PowerShell. You could use a library like MSAL or ADAL (just google your favoured method) or use a library less approach which I've included with this script . Whatever way you do this you need to make sure that your application registration  https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-

How to access and restore deleted Items (Recoverable Items) in the Exchange Online Mailbox dumpster with the Microsoft Graph API and PowerShell

As the information on how to do this would cover multiple posts, I've bound this into a series of mini post docs in my GitHub Repo to try and make this subject a little easier to understand and hopefully navigate for most people.   The Binder index is  https://gscales.github.io/Graph-Powershell-101-Binder/   The topics covered are How you can access the Recoverable Items Folders (and get the size of these folders)  How you can access and search for items in the Deletions and Purges Folders and also how you can Export an item to an Eml from that folder How you can Restore a Deleted Item back to the folder it was deleted from (using the Last Active Parent FolderId) and the sample script is located  https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Dumpster.ps1

Using the MSAL (Microsoft Authentication Library) in EWS with Office365

Last July Microsoft announced here they would be disabling basic authentication in EWS on October 13 2020 which is now a little over a year away. Given the amount of time that has passed since the announcement any line of business applications or third party applications that you use that had been using Basic authentication should have been modified or upgraded to support using oAuth. If this isn't the case the time to take action is now. When you need to migrate a .NET app or script you have using EWS and basic Authentication you have two Authentication libraries you can choose from ADAL - Azure AD Authentication Library (uses the v1 Azure AD Endpoint) MSAL - Microsoft Authentication Library (uses the v2 Microsoft Identity Platform Endpoint) the most common library you will come across in use is the ADAL libraries because its been around the longest, has good support across a number of languages and allows complex authentications scenarios with support for SAML etc. The
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.