Tuesday, February 12, 2008

Version 4 of the Mailbox Size Gui and using Quotas in Mailbox Size Reports

Version 5 has now been posted that fixes issue with quotas please see this

Based on the feedback and requests I’ve received I’ve updated the Mailbox Size Gui to show the percent of Quota used by each user. While this was not hard to do it’s unfortunately not as simple as just pulling the information from the get-mailboxstatistics cmdlet. As I’ve shown in other posts before when you what to determine the Quota that applies to a user’s mailbox you need to check quota information in a number of locations. The first place you need to check is the users account to see whether then have the use store quotas defaults set to true of false. Within a Get-mailboxstatitics operation there is a property made available called UseDatabaseQuotaDefaults which can be used to do this. If this property returns false then the quota information will be set on the User's Mailbox itself (or more accurately the User object in Active Directory) so in this case you can use the Get-Mailbox cmdlet to retrieve the ProhibitSendReceiveQuota property on the user account. If the UseDatabaseQuotaDefaults is set to true the you need to find out which Mailstore the Mailbox is located on and then check the Mailstores quotas setting using the get-mailboxdatabase cmdlet. If you want to do this for a number of users you could pipleline it a few different ways the way I’ve chosen to do this in my Mailbox GUI script is to create 2 hashtables to store any MailStore and UserMailbox quotas and then during the get-mailboxstatisitics cmd use these Hashtables to determine the percent of Quota the user has actually used. Here’s a quick sample

$mstoresquotas = @{ }
get-mailboxdatabase -server servername | ForEach-Object{
$_.identity
$_.ProhibitSendReceiveQuota
if ($_.IsUnlimited -ne $true){
$mstoresquotas.add($_.identity,$_.ProhibitSendReceiveQuota)
}

}

$usrquotas = @{ }
Get-Mailbox -server servername -ResultSize Unlimited | foreach-object{
if($_.ProhibitSendQuota -ne "unlimited"){
$usrquotas.add($_.ExchangeGuid,$_.ProhibitSendReceiveQuota)
}
}

get-mailboxstatistics | ForEach-Object{
$quQuota = "unlimited"
if ($_.UseDatabaseQuotaDefaults -eq $false){
if ($usrquotas.ContainsKey($_.MailboxGUID)){
$quQuota = "{1:P0}" -f ($_.TotalItemSize.Value.ToMB()/$usrquotas[$_.MailboxGUID].Value.ToMB())
}
}
else{
if ($mstoresquotas.ContainsKey($_.database)){
$quQuota = "{1:P0}" -f ($_.TotalItemSize.Value.ToMB()/$mstoresquotas[$_.database].Value.ToMB())}
}
$quQuota
}

What’s next when I get time I want to add a history feature so that every time you run the Gui it will record the result to an XML file so that the next time you run it in a week or months time it can then show you how much each mailbox has grown since. Also I’d like to come up with a cmd-line version that will output the result to a HTML Email with all the same functions. If anyone has any other idea’s they would like to see please let me know and I’ll see what I can do.

I’ve put a download of the new version here.

37 comments:

Jaap said...

Hi Glen,

Super script but 1 little typo in version 4. DelItems collumn name is in MB but output is in KB. Bit confusing havind delited items of 61 GB ;-)

Jaap

Jaap said...

Oh,

using typo's myself also. Sorry for that ;-)

Anonymous said...

Thanks for this script. Do I have to do any type of impersonation for this script to be fully functional?

Glen said...

No it uses the Get-MailboxFolderStatistics cmdlet which only requires that you have some form of delegated Exchange Admin rights.

Jaap: Thanks i actually meant to show the deleted items as MB i changed the label be not the code I've fixed this now

Cheers
Glen

Col said...

Hi - maybe I am doing something stupid but I keep getting the following error when running the script:-


The term 'Get-MailboxServer' is not recognized as a cmdlet, function, operable
program, or script file. Verify the term and try again.
At C:\mbsizereportv4.ps1:195 char:18
+ Get-MailboxServer <<<< | ForEach-Object{$snServerNameDrop.Items.Add($_.Name)
}
0
1
Cancel

Thanks

Glen said...

This script uses the Exchange Management Shell cmdlets (get-mailbox etc) so you need to run it from a machine that has the Exchange 2007 Management Tools installed. You need to run it from within the Exchange management shell (or else you can load the Exchange Management shell snapin in a normal powershell session). see http://technet.microsoft.com/en-us/library/bb123778.aspx

Cheers
Glen

Anonymous said...

If I try to run this cmdlet I get an error that it isn't digitally signed and therefore can't be run. What am I doing wrong?

Glen said...

If you right click the file in Windows explorer select properties. Then down the bottom of the properties dialouge there is a section called Security. Select Unblock.

Cheers
Glen

Anonymous said...

Thanks, that was the problem.

Matt said...

Hi Glen,

Great script! It's very useful to us. I just want to report that it freaked out when we disabled quotas (only leaving warnings) for our users though. :)

Lots of "You cannot call a method on a null-valued expression.
At C:\mbsizereportv4.ps1:84 char:97" and the "Get folder size" button stops working.

It's still very useful, but I thought I would mention it.

Matt

Glen said...

Thanks Matt appreciate the bug reports i'll look into that problem and see if i can reproduce and fix it.

Cheers
Glen

Anonymous said...

How to run at all? .ps1 not recognized, try to click/run with powershell it flashes open an closes.

Glen said...

You wont be able to run this script from a double click you need to start up the Exchange Management Shell and run it from within the Shell eg c:\mbsizereportv4.ps1

Cheers
Glen

Glen said...

Okay i've fixed that bug and updated the download. A point to note is that this script only check hardset quotas. Checking warning is something i'll look at in the next version

cheers
Glen

Anonymous said...

I just wanted to say thanks for your work on this script. This help me very much!

Matt said...

Hi Glen,

Thanks for the bug fix! Now the "quota errors" are gone.

But I can report that the "Get folder size" button sometimes doesn't work. Randomly, it seems, nothing happens when I click on it and the error is:

You cannot call a method on a null-valued expression.
At C:\mbsizereportv4.ps1:114 char:50
+ write-host $siSIDToSearch.SamAccountName.ToString( <<<< )
You cannot call a method on a null-valued expression.
At C:\mbsizereportv4.ps1:115 char:67
+ Get-MailboxFolderStatistics $siSIDToSearch.SamAccountName.ToString( <<<< ) |
ForEach-Object{

It's not related to a certain user, sometimes it works for user X, sometimes not.

/Matt

Glen said...

Thanks again Matt I'll see if i can put some verification code in the next version which may address that problem

Cheers
Glen

Anonymous said...

Hi Glen,

Super Job about the script. been using it since v1. but i have a few problems
i cant get the folder size cuz i am using aliases instead of the nt user ids for mailbox names. so while it gives me the sizes in full i cant see the individual sizes in detail.

any help with this pls?

red

DataJugglerScott said...

Glenn,

I love this tool!

A great feature would be a way to click one button and dump the store details to a separate file for each user so that we could demonstrate to each user how much space all of those joke folders that they have really waste.

Keep up the great coding and thanks!

Glen said...

for the issue with alias what you could try is replacing the line


Get-MailboxFolderStatistics $siSIDToSearch.SamAccountName.ToString() | ForEach-Object{

with


Get-MailboxFolderStatistics $siSIDToSearch.WindowsEmailAddress.ToString() | ForEach-Object{

or

Get-MailboxFolderStatistics $siSIDToSearch.DisplayName.ToString() | ForEach-Object{

or

Get-MailboxFolderStatistics $siSIDToSearch.UserPrincipalName.ToString() | ForEach-Object{

Cheers
Glen

Anonymous said...

thanks very much great little script... now just if MS had left it in the gui like it was in Ex03

Anonymous said...

Thanks Glen. Works fine!
Just a quick question: is it really MB in DelItems row?
It shows, for example, John Smith , #items 5044, MB Size 436MB, DelItems 90315 Mb.
If not, can you fix this?

Glen said...

Yeah sounds like another bug to me it sounds like its returning KB instead of MB for some reason. I'll have a look when i get a chance and post a fix.

Cheers
Glen

Shalamar said...

Wow, Dude this Rocks! I have a question, is there a way I can make it show the database that the user is in? If not no big deal this helps tremendously! Thank you for sharing this with everyone

Chris Parker said...

Hey Glen,

Awesome script! Thanks for taking the time to work on something like this for all of us. :-)

I'm not a big script/coder person, but I'd like to modify the script to allow me to specify a target domain controller. We have mailbox users in multiple subdomains and the get folder statistics fails because it can't find the user on whatever parent domain controller the powershell console chose at launch. I was thinking a variable $targetdc, but I can't tell where I should plug it in.

Any suggestions? Thanks.

Adam said...

Great script. Do you know of a way to view the sub-folders of a specific mailbox (inbox), and possibly the number of items or any other details about it?

Adam

Adam said...

Hi Glen,

I have answered my own question. It appears that if the mailbox has sub-folders they do indeed show up.

Anonymous said...

Hi Glen,

Thanks for your work on the script - excellent tool.

Sean

Daniel said...

Glen,

I haven't used the script as yet but I gather that it works as advertised. Your hard work is appreciated. Although the commercial reporting tools for Exchange do much more, this script addresses a crucial need. This script will produce the data that I need to charge back to our departments fairly. Your script may also save me tens of thousands of dollars in licenses for software packages that could provide mailbox-usage data, but deliver many features I don't need.

Anonymous said...

Glen,

This is a great tool. Would it be possible to add the mail database that the user is a part of to the export file?

Thanks

Glen said...

Its possible to add the database to the export file but not that practical with this version of the script im working on a new version that creates a CSV for each run as a history it would be easy to put that in with this version and wouldn't affect anything else. Should be up in a few days

Cheers
Glen

CDDSystems said...

All quotas are listed as 0... but every one of our users have quotas. One in particular is on the "warning" status but again that quot number is 0... any ideas?

Glen said...

Yeah sorry there where some bugs in the quota code please look at the new version http://gsexdev.blogspot.com/2008/05/version-5-of-mailbox-size-gui-script.html

Cheers
Glen

Anonymous said...

a command line email output would be awesome, this is what I was looking for. Nonetheless, it seems like a great program!

keith said...

When I try to "Get Folder Size", I receive the following error:

ForEach-Object : Cannot convert argument "0", with value: "0 B (0 bytes)", for "Round" to type "System.Decimal": "Cannot convert the "0 B (0 bytes)" value of type "Microsoft.Exchange.Data.ByteQuantifiedSize" to type "System.Decimal"."
At C:\mbsizereportv4.ps1:115 char:86
+ Get-MailboxFolderStatistics $siSIDToSearch.SamAccountName.ToString() | ForEach-Object <<<< {
+ CategoryInfo : NotSpecified: (:) [ForEach-Object], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument,Microsoft.PowerShell.Commands.ForEachObjectCommand

Thank you!

StephenCD said...

When I run the Script I am getting errors on Exchange 2010, is this the case?

Glen said...

if you have 2010 use the 2010 version http://gsexdev.blogspot.com/2010/03/mailbox-size-gui-exchange-2010-remote.html

Cheers
Glen