PowerShell GUI - Listview with top 30 mailboxes

Evgeny Shupik 191 Reputation points
2023-02-15T14:21:31.84+00:00

Hello everybody! Need some help - trying to create PowerShell script to show top30 mailboxes (depends of size):


$listMailboxesSize=Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30


foreach ($item in $listMailboxesSize)
{
   $i = New-Object System.Windows.Forms.ListViewItem($item.DisplayName)
   $i.SubItems.Add([string]$item.TotalItemSize)
   $listView.Items.Add($i) | Out-Null

}

$frmMain.Controls.Add($listView)

It works but there is no ordering by size in this example. What should I add in this code to make it possible? Thank you.

Exchange | Exchange Server | Other
Exchange | Exchange Server | Management
Windows for business | Windows Server | User experience | PowerShell
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2023-02-16T03:38:46.3866667+00:00

    Are these mailboxes in your on-premises organization or Office 365?

    If they're O365 mailboxes, try this:

    Get-MailboxStatistics | 
        Select-Object DisplayName, @{Name="TotalItemSizeMB"; Expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),0)}} |
            Sort-Object TotalItemSizeMB
    

  2. Franky 106 Reputation points
    2023-02-19T11:04:18.03+00:00

    you can also try Exchange Reporter (script is in english)

    https://www.frankysweb.de/exchange-reporter-2013/

    0 comments No comments

  3. Evgeny Shupik 191 Reputation points
    2023-02-24T15:26:46.73+00:00

    Here is a little investigation - I run all the same script using PS and using my GUI so the difference you can see on screens below. Looks like the problem is with a variable $listMailboxesSize. It already takes value as a list without ordering. How can it be?listMailboxesSize_command

    listMailboxesSize_var

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.