Link to home
Start Free TrialLog in
Avatar of mawatson
mawatson

asked on

Combine Get-MailboxFolderStatistics and Get-Mailbox

Hey folks.

I've recently been asked to slightly amend a simple Exchange Management Shell one-liner I put together a while ago.

It goes like this:

"ServerName" | Get-MailboxServer | Get-Mailbox -ResultSize unlimited | Get-MailboxFolderStatistics | where {$_.ItemsInFolder -gt 4700} | Sort-object -descending ItemsInFolder | ft Identity, FolderPath, ItemsInFolder, @{Label="FolderSize(MB)";expression={$_.FolderSize.ToMB()} }, @{Label="FolderSize(MB)";expression={$_.FolderAndSubfolderSize.ToMB()} } -a | out-file C:\ServerName-HighItemCount.txt -width 750

It will get the mailbox server, get each mailbox on said server and then get mailbox folder statistics where ItemsInFolder is greater than 4700 items.  It'll sort the output descending by ItemsInFolder and dump out several other properties of the object.

However, what Get-MailboxFolderStatistics does not do is show the Database or StorageGroup property of the mailbox.  So, is there a way I can sort combine the two to show the StorageGroup property of the mailbox in question??  Perhaps with a variable?

Any help is much appreciated.

Cheers,
Matt
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mawatson
mawatson

ASKER

That was a stroke of genius, Chris-Dent.  Nice one.

I took what you proposed and morphed it a bit to get this:

"ServerName" | Get-MailboxServer | Get-Mailbox -ResultSize unlimited | %{
$Mailbox = $_
  Get-MailboxFolderStatistics $_.Identity | ?{ $_.ItemsInFolder -gt 100 } | `
    Select-Object Identity, FolderPath, ItemsInFolder, `
      @{n='FolderAndSubfolderSize(MB)';e={ $_.FolderAndSubfolderSize.ToMb() }}, `
      @{n='Database';e={ $Mailbox.Database }}
} | Sort-object -descending ItemsInFolder | ft -a | out-file C:\Server_FolderList.txt -width 750


Many many thanks for the feedback.  This will be a helpful primer as reference for combining Exch Mgmt Shell cmdlets.

Cheers,
Matt