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

Export calendar Items to a CSV file using EWS and Powershell

Somebody asked about this last week and while I have a lot of EWS scripts that do access the Calendar I didn't have a simple example that just exported a list of the Calendar events with relevant information to a CSV file so here it is. I've talked on this one before in this howto  but when you query the calendar folder using EWS you need to use a CalendarView which will expand any recurring appointments in a calendar. There are some limits when you use a calendarview in that you can only return a maximum of 2 years of appointments at a time and paging will limit the max number of items to 1000 per call. So if you have a calendar with a very large number of appointments you need to break your query into small date time blocks. In this example script I'm just grabbing the next 7 days of appointments if you want to query a longer period you need to adjust the following lines (keeping in mind what I just mentioned) #Define Date to Query $StartDate = (Get-Date) $EndDate

Writing a simple scripted process to download attachmentts in Exchange 2007/ 2010 using the EWS Managed API

Every complicated thing in life is made up of smaller simpler building blocks, when it comes to writing a script (or any code really) the more of these little building blocks you have to figure out the more the process of solving a problem can become bewildering. The Internet generally provides you with lots of half eaten sandwiches of information something someone else has taken a bite out but a lot of the time half done, and as with any code its usefulness declines over time as new and better API's and methods are derived. In this post I'm going to go through a simple scripted process that hopefully covers a few more of these smaller building blocks that you might face when asked to come up with a simple costless solution to perform an automated business function with a script. So the process im going to look at is one that comes up a lot and that is you have an Email that comes into to certain mailbox every day with a certain subject in my case "Daily Export" this

Downloading a shared file from Onedrive for business using Powershell

I thought I'd quickly share this script I came up with to download a file that was shared using One Drive for Business (which is SharePoint under the covers) with Powershell. The following script takes a OneDrive for business URL which would look like https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filename.txt This script is pretty simple it uses the SharePoint CSOM (Client side object Model) which it loads in the first line. It uses the URI object to separate the host and relative URL which the CSOM requires and also the SharePointOnlineCredentials object to handle the Office365 SharePoint online authentication. The following script is a function that take the OneDrive URL, Credentials for Office365 and path you want to download the file to and downloads the file. eg to run the script you would use something like ./spdownload.ps1 ' https://mydom-my.sharepoint.com/personal/gscales_domain_com/Documents/Email%20attachments/filena
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.