When I pass a single mailbox to Get-Mailbox, it works fine, but when I pass all mailboxes (as in this example) the last couple columns are blank. I can’t figure out what I’m doing wrong!!

get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize,@{n="TotalItemSize";e={(Get-MailboxStatistics $_).TotalItemSize}},@{n="TotalDeletedItemSize";e={(Get-MailboxStatistics $_).TotalDeletedItemSize}},@{n="StorageLimitStatus";e={(Get-MailboxStatistics $_).StorageLimitStatus}},@{n="ItemCount";e={(Get-MailboxStatistics $_).ItemCount}} | out-gridview -title "report"
8 Spice ups

It might be a thing to make it a script rather than a single liner! That would make it much easier to troubleshoot, so let me give that a go real quick.

2 Spice ups

I confirmed the issue and did a google search. Others have the same problem. I also, now remember having this issue in the past too. Get-MailboxStatistics doesn’t like the pipeline. Loop thru the mailboxes instead.

$results = ForEach($mb in (get-mailbox -resultsize unlimited)){
    $mb | Select-Object ....
}
$results | Out-GridView

3 Spice ups

Ah, and you know, I think I figured out why. For each of your Get-MailboxStatistics, use $_.UserPrincipalName. Since you are modifying the original Get-Mailbox cmdlet, you are not passing a complete mailbox object through the pipeline, so Get-MailboxStatistics is not able to resolve it.

get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize,@{n="TotalItemSize";e={(Get-MailboxStatistics $_.UserPrincipalName).TotalItemSize}},@{n="TotalDeletedItemSize";e={(Get-MailboxStatistics $_.UserPrincipalName).TotalDeletedItemSize}},@{n="StorageLimitStatus";e={(Get-MailboxStatistics $_.UserPrincipalName).StorageLimitStatus}},@{n="ItemCount";e={(Get-MailboxStatistics $_.UserPrincipalName).ItemCount}} | out-gridview -title "report"

EDIT: I take that back… I can’t actually get it to work. cduff is right!

1 Spice up

And here’s the final script I came up with:

$mboxes = get-mailbox -resultsize unlimited | Select-Object DisplayName,UserPrincipalName,UseDatabaseRetentionDefaults,RetainDeletedItemsFor,IsMailboxEnabled,RecipientLimits,UseDatabaseQuotaDefaults,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,MaxSendSize,MaxReceiveSize
ForEach($mbox in $mboxes)
{
	$mboxStats = Get-MailboxStatistics $mbox.DisplayName
	$mbox | Add-Member -Name TotalItemSize -MemberType NoteProperty -Value $mboxStats.TotalItemSize
	$mbox | Add-Member -Name TotalDeletedItemSize -MemberType NoteProperty -Value $mboxStats.TotalDeletedItemSize
	$mbox | Add-Member -Name StorageLimitStatus -MemberType NoteProperty -Value $mboxStats.StorageLimitStatus
	$mbox | Add-Member -Name ItemCount -MemberType NoteProperty -Value $mboxStats.ItemCount
}
$mboxes | Out-GridView

You could use the Select-Object like you were before, but I just like the Add-Member for the ease of reading.

EDIT: Fixed two mistakes

3 Spice ups

@Twon of An:

That script is returning 1 result, and also produces this error:

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "" to type "Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter". Error: "Parameter values of type Microsoft.Exchange.Configuration.Tasks.GeneralMailboxIdParameter can't be empty. Specify a value, and try again.
Parameter name: identity"
    + CategoryInfo          : InvalidData: (:) [Get-MailboxStatistics], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxStatistics

Ah, you know what, your mailboxes might not all have the UserPrincipalName property filled in. Try using DisplayName instead.

I’ve edited the original script to reflect that.

1 Spice up

That fixed the error! Still just 1 result appearing in the grid window, though.

This is a massive ‘Doh’ moment… Change the last instance of $mbox to $mboxes! That will reference the entirety of the information.

1 Spice up

Need to do this

$modified_mboxes = ForEach....

$modified_mboxes | out-gridview
1 Spice up

Success! Thank you!