Udostępnij za pośrednictwem


Some Handy Exchange Mailbox and Database Size Powershell One-Liners

I wrote this up a while ago to share with customers and colleagues, but I never really posted it anywhere.  If you look at my previous post about using add-member, you might wonder why then I am using select-object here to create calculated properties which changes the pipeline to PSCustom objects...because I wrote this a while ago :)

If I were to write this again today, I would use Add-member instead and preserve the original objects.  Anyway, I hope this helps some folks out there!

 Update: I have re-written the malibox database size samples. Check out this newer blog post: Get Exchange Mailbox Database Size – One-Liner – Version 2

Getting mailboxdatabase sizes:

 

The examples below might not work on windows 2008 clusters due to CMS names and share scoping for the admin shares, it wouldn’t take a lot of work around this problem.

 

List out mailbox database sizes from largest to smallest.  If you take off the format cmdlet from the end you can pipe the object into whatever…export…format…convert…   This exmaple works against all E2K7 and legacy server DBs

 

[PS] C:\>get-mailboxdatabase -includepre | foreach-object{select-object -inputobject $_ -property *,@{name="MailboxDBSizeinGB";expression={[math]::Round(((get-item ("\\" + $_.servername + "\" + $_.edbfilepath.pathname.replace(":","$"))).length / 1GB),2)}}} | Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB -autosize

 

Identity MailboxDBSizeinGB

-------- -----------------

EXCH01\Storage Group 1-1\Mailbox Store 1-1-1 85.25

EXCH01\SG24\SG24-S1 69.87

EXCH01\SG30\SG30-S1 67.6

EXCH01\SG11\SG11-S1 66.36

EXCH01\SG48\SG48-S1 65.81

EXCH01\SG49\SG49-S1 64.43

EXCH02\SG23\SG23-S1 64.27

...

 

List out mailbox database sizes from largest to smallest.  If you take off the format cmdlet from the end you can pipe the object into whatever…export…format…convert…   This example only works against E2K7

 

[PS] C:\>get-mailboxdatabase | foreach-object{select-object -inputobject $_ -property *,@{name="MailboxDBSizeinGB";expression={[math]::Round(((get-item ("\\" + $_.servername + "\" + $_.edbfilepath.pathname.replace(":","$"))).length / 1GB),2)}}} | Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB -autosize

 

Identity MailboxDBSizeinGB

-------- -----------------

EXCH01\SG24\SG24-S1 69.87

EXCH01\SG30\SG30-S1 67.61

EXCH01\SG11\SG11-S1 66.36

EXCH01\SG48\SG48-S1 65.81

EXCH01\SG49\SG49-S1 64.43

...

 

Get general stats about mailbox databases in the org (legacy and E2K7)

 

[PS] C:\>get-mailboxdatabase -includepre | foreach-object{select-object -inputobject $_ -property *,@{name="MailboxDBSizeinGB";expression={[math]::Round(((get-item ("\\" + $_.servername + "\" + $_.edbfilepath.pathname.replace(":","$"))).length / 1GB),2)}}} | Sort-Object mailboxdbsizeinGB -Descending | measure-object -Property mailboxdbsizeinGB -Sum -Maximum

-Minimum -Average

                                                                                                                                         

Count : 111

Average : 48.5356756756756

Sum : 5387.46

Maximum : 85.25

Minimum : 0

Property : MailboxDBSizeinGB

 

 

 

Getting Average Mailbox Sizes:

 

In the examples below I am creating a custom property called CombinedTotalItemSizeinMB which is a combination of the total mailbox size plus the dumpster.

 

Note: When running a large get-malibox operation you may want to consider not showing warnings and errors.  Errors can be supressed during the get-mailbox cmdlet with the -erroraction param as shown below.  For warnings though you can set a special variable called $warningpreference to "silentlycontinue" before you run the command: PS:/ > $warningpreference = "silentlycontinue"

 

Display a table of mailbox sizes (this can take a while in a big org)

 

get-mailbox -resultsize unlimited -erroraction silentlycontinue | Get-MailboxStatistics | select-object *,@{name="TotalItemSizeinMB";expression={[math]::Round($_.totalitemsize.value.ToBytes() / 1MB,2)}},@{name="TotalDeletedItemSizeinMB";expression={[math]::Round($_.totaldeleteditemsize.value.ToBytes() / 1MB,2)}},@{name="CombinedTotalSizeinMB";expression={[math]::Round($_.totalitemsize.value.ToBytes() / 1MB,2) + [math]::Round($_.totaldeleteditemsize.value.ToBytes() / 1MB,2)}} | sort-object combinedtotalsizeinMB -Descending | format-table displayname,*MB

 

Display General Mailbox Stats Regarding Size (in the first example $mailboxsizelist is just a variable I set using the above command without the format-table on the end, the second requires no pre-action)

 

$mailboxsizelist | measure-object combinedTotalSizeinMB -sum -ave -max -min

 

Or

 

get-mailbox -resultsize unlimited -erroraction silentlycontinue | Get-MailboxStatistics | select-object *,@{name="TotalItemSizeinMB";expression={[math]::Round($_.totalitemsize.value.ToBytes() / 1MB,2)}},@{name="TotalDeletedItemSizeinMB";expression={[math]::Round($_.totaldeleteditemsize.value.ToBytes() / 1MB,2)}},@{name="CombinedTotalSizeinMB";expression={[math]::Round($_.totalitemsize.value.ToBytes() / 1MB,2) + [math]::Round($_.totaldeleteditemsize.value.ToBytes() / 1MB,2)}} | sort-object combinedtotalsizeinMB -Descending | measure-object combinedTotalSizeinMB -sum -ave -max -min

 

Display stats about the percentage of mailboxes that consume the total space ($mailboxsizelist is just a variable I set using the above command without the format-table on the end, you can definitely do this like above and simply insert the big line into each place the var appears, but that would be one hell of a long one-liner :) )

 

[PS] C:\>1..10 | foreach-object{"The top $($_*10) percent of the mailboxes consume $([int]((($mailboxsizelist | select-object -first ($mailboxsizelist.count * ($_ / 10)) | measure-object CombinedTotalSizeinMB -sum).sum / ($mailboxsizelist | measure-object combinedtotalsizeinMB -sum).sum) * 100)) percent of the Size of all the mailboxes."}

                                                                                                                                             

The top 10 percent of the mailboxes consume 41 percent of the Size of all the mailboxes.

The top 20 percent of the mailboxes consume 62 percent of the Size of all the mailboxes.

The top 30 percent of the mailboxes consume 76 percent of the Size of all the mailboxes.

The top 40 percent of the mailboxes consume 86 percent of the Size of all the mailboxes.

The top 50 percent of the mailboxes consume 93 percent of the Size of all the mailboxes.

The top 60 percent of the mailboxes consume 97 percent of the Size of all the mailboxes.

The top 70 percent of the mailboxes consume 99 percent of the Size of all the mailboxes.

The top 80 percent of the mailboxes consume 100 percent of the Size of all the mailboxes.

The top 90 percent of the mailboxes consume 100 percent of the Size of all the mailboxes.

The top 100 percent of the mailboxes consume 100 percent of the Size of all the mailboxes.

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm.

Comments

  • Anonymous
    January 01, 2003
    Thanks  //o//.  I fixed them up.  That was a page I wrote quite a while ago.  I should do a bit more review though of old stuff before I hit "publish"  :) Thanks again!

  • Anonymous
    January 01, 2003
    Hi Gary, there are 2 typos in the onliner : -erroraction siltentlycontinue and a double pipeline symbol : |   | measure-object   Greetings //o//

  • Anonymous
    January 01, 2003
    Very nice collection, I am now using the same syntax for approximate SharePoint database sizes! Was a great help