none
Mailbox Stats returning blank columns and not in descending order RRS feed

  • Question

  • I am trying to execute 3 powershell scripts to export mailboxstats to a csv file. My objective is to output

    Display Name, TotalItemCount, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota

    TotalItemCount to be displayed in "MB" and in Descending Order.

    Below is Script01

    I am able to get the output as desired but cannot get the TotalItemCount in Descending Order

    $users = Get-Mailbox -ResultSize Unlimited|select alias, Name,displayname,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,@{n='Firstname';e={$_.displayname.split(' ')[0]}},@{n='Lastname';e={$_.displayname.split(' ')[1]}}
    $users | % {
      $x = Get-MailboxStatistics $_.alias | Select TotalItemSize
      $t = New-Object PSObject -Property @{
    Name              = $_.Name
    Firstname         = $_.Firstname
    LastName          = $_.lastname
    IssueWarningQuota = $_.IssueWarningQuota       
    ProhibitSendQuota = $_.ProhibitSendQuota       
    ProhibitSendReceiveQuota = $_.ProhibitSendReceiveQuota     
    TotalItemSize    = $X.TotalItemSize
      }
    
    }

    Below is Script02, the ouput here shows TotalItemSize in MB & Descending Order but the columns "IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota" are empty.

    Get-Mailbox -ResultSize Unlimited |
    
    Get-MailboxStatistics |
    
    Select DisplayName
    
    @{name="TotalItemSize (MB)"; expression={[math]::Round( `
    
    ($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, `
    
    ItemCount, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota |
    
    Sort "TotalItemSize (MB)" -Descending

    Below is Script03, here again the ouput shows all columns however the TotalItemSize is not in Descending order.

    foreach($users in Get-Mailbox -ResultSize Unlimited){$users | Foreach-Object {
    
    $user = $_
    
    $stats = Get-MailboxStatistics $user.Name
    
    New-Object -TypeName PSObject -Property @{
    
    DisplayName = $User.DisplayName
    
    IssueWarningQuota = $User.IssueWarningQuota
    
    ProhibitSendQuota = $User.ProhibitSendQuota
    
    TotalItemSize = $stats.TotalItemSize
    
    }
    
    }
    
    }

    Appreciate if the powershell experts here can guide me on how to correct the above scripts and assist me in getting the desired output.


    Wednesday, May 22, 2019 8:02 AM

All replies

  • Hi,

    You can try the script below. It works in my lab.

    $output = @() $mailboxes = Get-Mailbox -server <servername> -RecipientTypeDetails UserMailbox foreach($mailbox in $mailboxes) { $stats = Get-MailboxStatistics $mailbox.alias $user = Get-ADUser $mailbox.alias $Results = New-Object psobject -Property @{ Name = $Mailbox.Name Firstname = $user.Firstname LastName = $user.lastname TotalItemSize = $stats.TotalItemSize IssueWarningQuota = $mailbox.IssueWarningQuota ProhibitSendQuota = $mailbox.ProhibitSendQuota ProhibitSendReceiveQuota = $mailbox.ProhibitSendReceiveQuota } $output += $Results } $output | Select Name, Firstname, LastName, TotalItemSize, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | Sort-Object TotalItemSize -Descending| Export-CSV <filepath>

    Regards,

    Dawn Zhou


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, May 23, 2019 3:07 AM
    Moderator
  • We are on Office365 Exchange Online

    $mailboxes = Get-Mailbox -server <servername> -RecipientTypeDetails UserMailbox

    Servername?

    Thursday, May 23, 2019 5:16 AM
  • We are on Office365 Exchange Online

    $mailboxes = Get-Mailbox -server <servername> -RecipientTypeDetails UserMailbox

    Servername?

    Well. You don't mention that in your first post, so I assume you are using Exchange 2016.

    For Exchange online, you can use the following script.

    $output = @()
    $mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox
    
    foreach($mailbox in $mailboxes)
    {
    $stats = Get-MailboxStatistics $mailbox.alias
    $Results = New-Object psobject -Property @{
                      Name = $Mailbox.Name
                      TotalItemSize = $stats.TotalItemSize
                      IssueWarningQuota = $mailbox.IssueWarningQuota
    		  ProhibitSendQuota = $mailbox.ProhibitSendQuota
    		  ProhibitSendReceiveQuota = $mailbox.ProhibitSendReceiveQuota
       } 
    $output += $Results
    }
    
    $output | Select Name, TotalItemSize, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota | Sort-Object TotalItemSize -Descending| Export-CSV <filepath>


    Regards,

    Dawn Zhou


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, May 23, 2019 5:51 AM
    Moderator
  • Apologies for not mentioning we are on Exchange 2016. However, I ran your script, it gives me everything I need but the TotalItemSize is not in Descending order.

    Thursday, May 23, 2019 6:30 AM
  • Apologies for not mentioning we are on Exchange 2016. However, I ran your script, it gives me everything I need but the TotalItemSize is not in Descending order.

    According to research, when you use EMS through a remote session, the result is returned as string which is sorted differently. Thus the script above doesn't work in Exchange online. Why don't you simply open the file by Excel and sort the TotalItemSize there?

    Regards,

    Dawn Zhou


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, May 24, 2019 9:52 AM
    Moderator
  • Hi,

    How is everything going?

    If there is anything unclear, please feel free to let me know. If the reply helps, kindly mark it as answer, which will be beneficial for answer searching in the forum.

    Thanks for your understanding.

     

    Regards,

    Dawn Zhou


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, May 30, 2019 9:22 AM
    Moderator