I am setting up a report to email myself mailbox stats but part of it is blank. Someone else tested it for themselves on their exchange server and it worked fine. so what is wrong with mine?

DisplayName : User Name

Database : mailboxdb01

TotalItemSize :

ItemCount :

IssueWarningQuota : unlimited

ProhibitSendQuota : unlimited

But the last six results do have the information that I am wanting.

My command

. 'E:\Exchange Binaries\Bin\RemoteExchange.ps1'
Connect-ExchangeServer –auto
Get-Mailbox | Select-Object Displayname, Database,
    @{Name='TotalItemSize'; Expression={[String]::join(";", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},
    @{Name='ItemCount'; Expression={[String]::join(";",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},
    IssueWarningQuota, ProhibitSendQuota |
  set-variable Result
Send-MailMessage -SmtpServer outlook -From noreply@ -To ronw@ -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join "`n")
5 Spice ups

Get-MailboxStatistics has issues when operating on a pipeline with multiple objects. I don’t know why. Here is a work around:

$mailboxes = Get-Mailbox 
$Result = ForEach ($mailbox in $mailboxes) { 
    $mailbox | Select-Object Displayname, Database,
    @{Name='TotalItemSize'; Expression={[String]::join(";", (Get-MailboxStatistics -identity $_.identity).TotalItemSize)}},
    @{Name='ItemCount'; Expression={[String]::join(";",(Get-MailboxStatistics -identity $_.identity).ItemCount)}},
    IssueWarningQuota, ProhibitSendQuota 
}
Send-MailMessage -SmtpServer outlook -From noreply@ -To ronw@ -Subject 'Mail Stats Report' -BodyAsHTML -Body (($Result | convertTo-HTML) -join "`n")

Here you are only sending single object down the pipe to Get-MailboxStatistics. And each iteration of the loop allows Get-MailboxStatistics to complete before moving on to the next one.

Got the email but it is totally blank. No text at all

Sorry, I put $Result as $Results. Change the typo and try again.

What I don’t like about that approach is calling Get-MailboxStatistics twice. Nothing really wrong with it but it is slow, and you’ve already gotten the data once so why do it twice? Here’s my approach that just does it once:

ForEach ($MB in (Get-Mailbox))
{   $MB | Get-MailboxStatistics | Select @{Name="DisplayName";Expression={$MB.DisplayName}},@{Name="Database";Expression={$MB.Database}},TotalItemSize,ItemCount,@{Name="IssueWarningQuota";Expression={$MB.IssueWarningQuota}},@{Name="ProhibitSendQuota";Expression={$MB.ProhibitSendQuota}}
}
1 Spice up

EDIT: Whoops, left the | Select -First 5 in there by accident, which I used for testing. Took that out!

lol yea the first 5 was throwing me off. Is it possible to sort-object itemsinfolder ?

Add:

$Result = $Result | Sort-Object ItemCount

between the loop and send-mailmessage

1 Spice up

My final result, worked perfect thanks everyone

(($Result | sort-object TotalItemSize -descending | convertTo-HTML) -join "`n")
1 Spice up