【发布时间】:2021-12-17 22:28:49
【问题描述】:
我需要报告一周内发送和接收的多个共享邮箱的电子邮件。目标是有 2 个表格,一个显示每个邮箱和他们收到的电子邮件的计数,按天分解,另一个表格显示相同但已发送的电子邮件。理想情况下应该如下所示:
| Mailbox | Received Monday | Received Tuesday | Received Wednesday |
|---|---|---|---|
| email@domain.com | 123 | 456 | 789 |
| email2@domain.com | 987 | 654 | 321 |
我能够获取每个邮箱的已发送和已接收电子邮件的计数,但我无法将这些结果格式化为表格。我已经尝试使用 Format-Table 来执行此操作,但它不会打印任何结果。
我哪里错了?
Param(
[DateTime] $start = '2021-12-07 00:00:00',
[DateTime] $end = '2021-12-07 23:59:59',
$emailSent1,
$emailReceived1,
$emailSent2,
$emailReceived2
)
function Get-Emails {
$emailSent1 = Get-MessageTrace -SenderAddress mailbox@domain.com -StartDate $start -EndDate $end
$emailReceived1 = Get-MessageTrace -RecipientAddress mailbox@domain.com -StartDate $start -EndDate $end
$emailSent2 = Get-MessageTrace -SenderAddress mailbox2@domain.com -StartDate $start -EndDate $end
$emailReceived2 = Get-MessageTrace -RecipientAddress mailbox2@domain.com -StartDate $start -EndDate $end
}
Get-Emails | Format-Table SenderAddress,$emailSent1.Count.ToString()
【问题讨论】:
-
Get-Emails函数从不输出任何内容 - 它只是将Get-MessageTrace调用的结果分配给四个局部变量,仅此而已。删除$emailSent1 =部分,对所有四个重复 -
如果我这样做,我也一无所获。我可以将 .Count 添加到那些给我结果的变量的末尾,但我无法将结果格式化为表格
-
虽然与您的问题无关,但我认为最好提及在发件人地址上使用消息跟踪可能会导致实际发送的电子邮件数量过多/夸大。这样做的原因是因为具有多个收件人的单个电子邮件将为每个收件人都有一个消息跟踪条目,为了准确起见,我建议按
MessageId属性分组,因为这对于单个电子邮件是唯一的,并且对于每个收件人都是相同的的收件人。
标签: powershell