Powershell - Office365 Exchange 入站和出站邮件

Powershell - Office365 Exchange inbound and outbound mail

尝试设置一个 PS 脚本来查询 O365 Exchange、检查入站邮件、计算所有入站邮件、returns 计数,并对出站执行相同的操作。

这是我目前所知道的,它一直返回相同数量的入站消息和出站消息,即 500500。

不确定会怎样,除非它是预设的最大值并且我已经达到了上限。

# initialize session
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

# O365 Inbound/Outbound tracking
$inbound = Get-MailTrafficReport -Direction Inbound | select "MessageCount" 
$inbound -replace "[()\s+]"

$i = $inbound
$(for($i=0;$i -le 1000; $i+=1){$i} ) | ForEach-Object -begin {$inbound_sum=0 }-process {$inbound_sum+=$_}
$inbound_sum

# send sum to streaming dataset? 
$outbound = Get-MailTrafficReport -Direction Outbound | select "MessageCount" 
$outbound -replace "[()\s+]"

$o = $outbound
$(for($o=0;$o -le 1000; $o+=1){$o} ) | ForEach-Object -begin {$outbound_sum=0 }-process {$outbound_sum+=$_} 
$outbound_sum

inbound_sum = outbound_sum?我在这里错过了什么?

我尝试删除迭代器行中的 [=11=] -le 1000,但它只是挂起。尽管如此,我怀疑将结果限制为 1000 是否会将入站和出站相加到完全相同的数字。

500 是 windows 管理帐户 uid,好像我已经达到了管理限制。

把它放在这里是因为它对于普通评论来说太长了。

根据 MS 文档、AD、Exchange 等设置了默认限制,这些限制是相对于一次 return 记录的数量设置的,除非您将其设置为无限制。请参阅有关该主题的文档。

但是,为什么不使用 MS Exchange/O365 内置的消息、监控、跟踪和日志记录来获取此 data/statistics?

Monitoring, reporting, and message tracing in Exchange Online

Microsoft 365 Reports in the admin center - Email activity

如果您不需要重新发明轮子(除非这是一个学习练习,或者您真的觉得您可以做得更好),因为默认 solution/service 已经提供了它。查看下面的脚本并根据需要进行调整。

Office 365 Mail Traffic Statistics by User

This script connects to Office 365 and retrieves the inbound and outbound mail traffic statistics by recipient for all available dates. This information is then exported to a CSV file which can be opened in Microsoft Excel.

Download: Get-DetailedMessageStats.ps1

Office 365 Exchange Auditing and Reporting - Mailbox Usage, Traffic Reports, etc

Get 160+ O365 Exchange reports on Incoming and Outgoing Mail Traffics, Spam/Malware Emails, Mailbox Forwarding, Mailbox Permissions, Mailbox Auditing, Non-Owner Access, Mailbox Login, Mailbox Size&Usage, Active & Inactive Mailboxes, Distribution Groups with their Membership etc

Download: Office365-Exchange-Tool.exe