eb17 eb17 - 3 months ago 17
PowerShell Question

Selected mailbox information missing in exported CSV file

I have been trying to export some mailbox statistics to Excel with

Export-Csv
. This is the script I came up with, but now I'm at a dead end:

Get-Mailbox |
select DisplayName, Alias, Database, TotalItemSize, ItemCount,
StorageLimitStatus, IssueWarningQuota, ProhibitSendQuota |
Export-Csv c:\xyz.csv


The problem I'm having is that it exports everything except
TotalItemSize
,
ItemCount
and
StorageLimitStatus
into the .csv file. I don't know what the issue is.

Answer

The object that Get-Mailbox returns doesn't not contain the property's you are trying to select. If you run the following command you will see a list of all properties available that Get-Mailbox can return.

Get-Mailbox | Get-Member -MemberType Properties

You will want to use Get-MailboxStatistics to get those properties:

Get-Mailbox "Your.Mailbox" | Get-MailboxStatistics |
    Select TotalItemSize, ItemCount, StorageLimitStatus

To get all the properties into the csv file you could create a custom object and export that:

Get-mailbox "Your.Mailbox" | %{
    $mb = $_
    $stats = $mb | Get-MailboxStatistics | Select TotalItemSize,ItemCount,StorageLimitStatus

    $Properties = @{ 
          DisplayName = $mb.DisplayName 
          Alias = $mb.Alias
          Database = $mb.Database
          IssueWarningQuota = $mb.IssueWarningQuota
          ProhibitSendQuota=$mb.ProhibitSendQuota
          TotalItemSize=$stats.TotalItemSize
          ItemCount=$stats.ItemCount
          StorageLimitStatus=$stats.StorageLimitStatus
    }

    New-Object psobject -Property $properties
} | Export-Csv c:\xyz.csv
Comments