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
mawatsonAsked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

Yes, you can. Although I don't believe in one-liners I'm afraid, too messy :)


Get-Mailbox -ResultSize Unlimited -Server "ServerName" | %{
  $Mailbox = $_
  Get-MailboxFolderStatistics $_.Identity | ?{ $_.ItemsInFolder -gt 4700 } | `
    Select-Object Identity, FolderPath, ItemsInFolders, `
      @{n='FolderSize(MB)';e={ $_.FolderSize.ToMb() }}, `
      @{n='FolderAndSubfolderSize(MB)';e={ $_.FolderAndSubfolderSize.ToMb() }}, `
      @{n='Database';e={ $Mailbox.Database }}
}


Or something like that, can't test it here, and I forget if "Get-Mailbox" exposes a StorageGroup Property.

It only uses ForEach-Object (%) because it leaves output in the pipeline. That lot be piped into whatever formatting options you like, whether that's Export-CSV, ConvertTo-Html, Format-Table, Out-GridView, or something else entirely. Just tack that onto the very end.

Chris
0
 
mawatsonAuthor Commented:
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
0
All Courses

From novice to tech pro — start learning today.