troubleshooting Question

Sorting Recoverable Items Size in Descending Order

Avatar of whatEVOwrx
whatEVOwrx asked on
Powershell
7 Comments1 Solution137 ViewsLast Modified:
Hello,

I have a script modified from various other scripts to match what I need.  Check the attached code.  I'm trying to Sort Recoverable Items Size by size in Descending order.  However I'm not getting results from big to small.

The below script works fine if I sort "Total Item Size (MB)".

$mailboxes = @(Get-Mailbox -Filter "RecipientType -eq 'UserMailbox'" -ResultSize 20)
$report = @()

ForEach ($mailbox in $mailboxes)
{
    $mbFolderStats = $mailbox | Get-MailboxFolderStatistics | where {$_.FolderType -eq ‘RecoverableItemsRoot’}
    $mbStats = $mailbox | Get-MailboxStatistics | Select-Object DisplayName, @{name="TotalItemSize (MB)";expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},ItemCount,TotalDeletedItemSize
    #Select-Object DisplayName, @{name=”TotalItemSize (GB)”;expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1GB),2)}},ItemCount,TotalDeletedItemSize -First 50

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name "Folder Path" -Value $mbFolderStats.Name
    $mbObj | Add-Member -MemberType NoteProperty -Name "Recoverable Items Size" -Value $mbFolderStats.FolderAndSubfolderSize
    $mbobj | Add-Member -MemberType NoteProperty -Name "Items in Folder" -Value $mbFolderStats.ItemsInFolderAndSubfolders
    $mbObj | Add-Member -MemberType NoteProperty -Name "Total Item Size (MB)" -Value $mbStats.'TotalItemSize (MB)'
    $mbObj | Add-Member -MemberType NoteProperty -Name "Item Count" -Value $mbStats.ItemCount
    $mbObj | Add-Member -MemberType NoteProperty -Name "Total Deleted Item Size" -Value $mbStats.TotalDeletedItemSize
    $report += $mbObj
    }
$report | Sort-Object "Recoverable Items Size" -Descending
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros