1

I have the sourcedata similar to the following denormalized table

DisplayName                  LogRecordCount LogRecordBytes
-----------                  -------------- --------------
Mailbox - Low,                    459          43756
Mailbox - Low,                    1628         185542
Mailbox - Low,                    2575         264474
Mailbox - Low,                     522          48813
Mailbox - Low,                     410         138212
Mailbox - Low,                    1057         200043
Mailbox - Freed                  3866        2170719
Mailbox - Freed                   606         370304
Mailbox - Freed                  4137        1939924
Mailbox - Freed                 3655        1654650

My goal is to write a summary similar to the following

DisplayName                  LogRecordCount  
-----------                  -------------- 
Mailbox - Low,                     6651            
Mailbox - Freed                   12264     

The following code is very close to getting what I need, but the "DisplayName" isn't appearing. The value of DisplayName is buried in the result of the Group-Object command.

$stats | ? {$_.DigestCategory -eq 'LogBytes'} | group MailboxGuid | %{
    New-Object psobject -Property @{
        MailboxGuid = $_.Name
        LogRecordBytes = ($_.Group | Measure-Object LogRecordBytes -Sum).Sum
        DisplayName   = $_.Group.DisplayName
    }
}| sort-object LogRecordBytes |  ft -a DisplayName, MailboxGuid, LogRecordBytes

Question

What is the proper syntax for DisplayName = $_.Group.DisplayName to display the display name in the results?

4

2 回答 2

1

用以下内容交换您的DisplayName = ..线路:

DisplayName = $_.Group | Select-Object -ExpandProperty DisplayName -Unique

如果由于某种神奇的原因,组中有不同DisplayName的值,你会得到一个类似的数组,{value1, value2},但通常它只会返回一个名称:)

于 2013-02-19T17:35:50.350 回答
0

Graimer 的答案非常好,但您也可以DisplayName从组的第一个元素中提取,假设所有组元素具有相同的值DisplayName

DisplayName = $_.Group[0].DisplayName

只是想让你知道另一种选择。

于 2013-02-19T19:59:07.313 回答