当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Exchange Online 中获取邮件跟踪

作者:精品下载站 日期:2024-12-14 09:11:59 浏览:15 分类:玩电脑

在 Exchange Online 中获取邮件跟踪


使用 Get-MessageTrace PowerShell cmdlet,您可以查看过去 10 天内在 Exchange Online 中发送和接收的每封邮件的信息。您还可以导出有关保存在 Exchange Online 中的所有传入和传出邮件的信息。在本文中,您将了解如何使用 Exchange Online PowerShell Get-MessageTrace cmdlet。

Exchange Online 消息跟踪

在基于 Exchange Online (Microsoft 365) 的环境中,Exchange Online 会注册每封传入和传出邮件。

有两种方式查看发送和接收的邮件信息:

  • 交易所管理中心
  • 在线交换 PowerShell

在本文中,我们将仅使用 Exchange Online PowerShell 并通过 PowerShell 命令 Get-MessageTrace 和 Get-MessageTraceDetail 来查询和导出邮件数据。

让我们开始列出 Get-MessageTrace PowerShell 命令的优点和缺点。

优点:

  • 查看和导出 Exchange Online 邮件的信息。
  • 快速有效地检索有关在 Exchange Online 中注册的邮件的信息。

缺点:

  • 您可以在最多 10 天内从 Exchange Online 服务器获取信息。 Exchange Online 保存邮件信息的期限为 90 天,但您无法获取超过 10 天的信息。
  • 您可以在 PowerShell 控制台上显示或导出到文件的信息是非常基本的信息,不包括有关特定邮件的详细信息。

注意:使用 Get-MessageTraceDetail PowerShell cmdlet 获取过去 10 天的其他信息。然而,信息仍然是基础的,结果返回的速度也较慢。

如果您需要有关超过 10 天的邮件的详细信息,请使用 Exchange Online 历史邮件跟踪报告一文中介绍的 Get-HistoricalSearch PowerShell 命令。它在报告中显示长达 90 天的数据。

连接到 Exchange Online PowerShell

为了能够运行 PowerShell 命令,您需要以管理员身份运行 Windows PowerShell 并连接到 Exchange Online PowerShell。

Connect-ExchangeOnline

连接后,继续下一步。

Get-MessageTrace PowerShell cmdlet

Get-MessageTrace PowerShell cmdlet 可以跟踪 Exchange Online 中的邮件。

使用 Get-MessageTrace PowerShell cmdlet 时,日期范围是一个重要组成部分。我们还将向 Get-MessageTrace 用户展示各种类型的示例,其中包含不同的参数和过滤器,例如发件人、收件人、主题、IP 地址等。

日期范围

最重要的构建块是日期范围。因此,最好使用定义日期范围的 PowerShell 参数。

注意: 使用 Get-MessageTrace 命令时,默认情况下只能获取最近 48 小时的数据。

这些 PowerShell 参数定义所需的日期范围:

  • 开始日期
  • 结束日期

提供有关所需日期范围的信息后,我们可以添加其他块来帮助我们过滤或缩小搜索结果。

我们将向您展示一些示例来缩小搜索结果范围:

  • 获取与特定发件人发送的电子邮件或特定收件人发送的电子邮件相关的邮件信息。
  • 获取与具有特定主题特定状态的电子邮件相关的邮件信息。

[玩转系统] 在 Exchange Online 中获取邮件跟踪

发件人与收件人

在许多场景中,我们通过添加过滤参数来过滤或缩小 Get-MessageTrace PowerShell 命令结果。

过滤器参数senderrecipient可能会令人困惑,因此澄清这些术语的含义非常重要。

  • 发件人:发送电子邮件的人。
  • 收件人:接收电子邮件的人。它与电子邮件发送到的目标实体相关。

下图显示了鲍勃向阿黛尔发送电子邮件的示例。 Bob 被定义为发件人 (SenderAddress),Adele 是收件人 (RecipientAddress)。

[玩转系统] 在 Exchange Online 中获取邮件跟踪

如果您想在使用 Get-MessageTrace cmdlet 时获取有关所有可用 PowerShell 参数的信息,可以在下一步中使用 Get-Member PowerShell 命令。

使用 Get-MessageTrace PowerShell 命令

运行以下 PowerShell 命令示例。

Get-MessageTrace | Get-Member

您将获得以下 PowerShell 输出示例。查看名称下列出的不同参数。

PS C:\> Get-MessageTrace | Get-Member

   TypeName: Deserialized.Microsoft.Exchange.Management.FfoReporting.MessageTrace

Name             MemberType Definition                                                                                                                                                               
----             ---------- ----------                                                                                                                                                               
GetType          Method     type GetType()                                                                                                                                                           
ToString         Method     string ToString(), string ToString(string format, System.IFormatProvider formatProvider), string IFormattable.ToString(string format, System.IFormatProvider formatPro...
EndDate          Property   System.DateTime {get;set;}                                                                                                                                               
FromIP           Property   System.String {get;set;}                                                                                                                                                 
Index            Property   System.Int32 {get;set;}                                                                                                                                                  
MessageId        Property   System.String {get;set;}                                                                                                                                                 
MessageTraceId   Property   System.Guid {get;set;}                                                                                                                                                   
Organization     Property   System.String {get;set;}                                                                                                                                                 
Received         Property   System.DateTime {get;set;}                                                                                                                                               
RecipientAddress Property   System.String {get;set;}                                                                                                                                                 
SenderAddress    Property   System.String {get;set;}                                                                                                                                                 
Size             Property   System.Int32 {get;set;}                                                                                                                                                  
StartDate        Property   System.DateTime {get;set;}                                                                                                                                               
Status           Property   System.String {get;set;}                                                                                                                                                 
Subject          Property   System.String {get;set;}                                                                                                                                                 
ToIP             Property    {get;set;} 

运行不带参数的 PowerShell cmdlet Get-MessageTrace 以显示过去 48 小时的数据。

Get-MessageTrace

PowerShell 输出结果。

PS C:\> Get-MessageTrace

Received            Sender Address                 Recipient Address              Subject                                                                                         Status        
--------            --------------                 -----------------              -------                                                                                         ------        
15/06/2023 19.45.30 [email protected]    [email protected]     RE: مرحبا كيف حالك                                                                                 Delivered     
15/06/2023 19.42.43 [email protected]     [email protected]    مرحبا كيف حالك                                                                                     Delivered     
15/06/2023 11.54.24 [email protected]              [email protected]    If you need paper notebook,Im here for you                                                      FilteredAsSpam
14/06/2023 11.22.44 [email protected] [email protected]           Your requested Report Amanda is now available                                                   Delivered     
14/06/2023 10.01.30 [email protected]       [email protected]           Get the latest Office apps                                                                      Delivered     
14/06/2023 08.56.40 [email protected]        [email protected] Undeliverable: Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available  Failed        
14/06/2023 08.56.39 [email protected] [email protected]           Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available                 Failed        
14/06/2023 01.57.05 [email protected]    [email protected]    Test your Junk mail!                                                                            FilteredAsSpam

要获取最近 10 天的数据,请继续执行下一步。

设置具体日期范围

如前所述,使用 Get-MessageTrace 命令时最基本的构建块是所需的日期范围。

日期范围是开始日期和结束日期之间的间隔。

请看下面的 Powershell 语法示例。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy>

Exchange Online 显示开始日期最多为 10 天的信息。

Get-MessageTrace -StartDate 04/01/2023 -EndDate 06/01/2023

如果您输入的开始日期距今天早于 10 天,或者日期范围大于 10 天,您将收到以下错误。

PS C:\> Get-MessageTrace -StartDate "05/01/2023" -EndDate "05/10/2023"
Write-ErrorMessage : |Microsoft.Exchange.Management.Tasks.ValidationException|Invalid 
StartDate value. The StartDate can't be older than 10 days from today.
At C:\AppData\Local\Temp\tmpEXO_ewmxedgo.0pb\tmpEXO_ewmxedgo.0pb.psm1:1120 
char:13
+             Write-ErrorMessage $ErrorObject
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-MessageTrace], ValidationException
    + FullyQualifiedErrorId : [Server=DB9PR02MB7211,RequestId=60294da4-119d-8a23-c31c-d9a9895 
   70a3a,TimeStamp=Wed, 07 Jun 2023 20:28:34 GMT],Write-ErrorMessage

注意:如果 StartDate 早于今天 10 天,您将收到错误消息。此外,StartDate 和 EndDate 之间的日期范围不得超过 10 天。

当使用Get-MessageTrace命令时,我们可以使用两种主要的语法方法来定义日期范围。

  • (月/日/年)格式手动输入特定日期(开始日期和结束日期) )。
  • 或者使用 PowerShell cmdlet Get-Date

我们更喜欢使用的第二种方法是 PowerShell 函数 Get-Date。

顾名思义,Get-Date PowerShell cmdlet 将获取有关当前日期和时间的信息。这些信息包括秒、分、时、日、月和年。

使用 Get-MessageTrace cmdlet 时,Get-Date PowerShell 函数定义结束日期。您可以使用 AddHoursAddDays 等时间单位并从当前日期中减去它们来定义开始日期。

在以下示例中,我们使用时间单位 AddDays 和值 (-10) 定义 10 天的日期范围。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -Enddate (Get-Date)

此语法告诉 PowerShell,我们要定义一个通过从 Get-Date PowerShell cmdlet 获取的当前时间减去 10 天 计算得出的日期。

Get-MessageTrace 特定日期范围内的数据

获取有关特定日期范围内发送或接收的电子邮件的信息。通过手动键入 StartDateEndDate 来指定日期。

运行以下 PowerShell 命令示例。

Get-MessageTrace -StartDate 06/05/2023 -EndDate 06/10/2023

PowerShell 输出示例。

PS C:> Get-MessageTrace -StartDate 06/05/2023 -EndDate 06/10/2023

Received            Sender Address                             Recipient Address           Subject                                                                      Status        
--------            --------------                             -----------------           -------                                                                      ------        
09/06/2023 10.13.47 [email protected]                     [email protected]  This is a test                                                               Delivered     
09/06/2023 10.04.16 [email protected]                     [email protected] Re: Test                                                                     Delivered     
09/06/2023 10.01.37 [email protected]                [email protected]      Test                                                                         Delivered     
09/06/2023 09.58.06 [email protected]                 [email protected] RE: Available                                                                Delivered     
09/06/2023 09.56.06 [email protected]                [email protected]  Available                                                                    Delivered     
07/06/2023 21.15.32 [email protected]          [email protected]  All parties have Completed: Please DocuSign`M365info                         FilteredAsSpam
07/06/2023 12.32.00 [email protected]           [email protected]    All parties have Completed: Please DocuSign:`[email protected]        FilteredAsSpam
07/06/2023 06.55.21 [email protected]          [email protected]  All parties have Completed: Please DocuSign: M365info`                       FilteredAsSpam
06/06/2023 21.30.03 [email protected] [email protected]     Approved: Completed: Please DocuSign: M365info`                              FilteredAsSpam
06/06/2023 20.34.22 [email protected]                     [email protected] Test your Junk mail!                                                         FilteredAsSpam
06/06/2023 20.25.41 [email protected]                     [email protected] Just a test!                                                                 Delivered     
06/06/2023 19.22.32 [email protected] [email protected]    Completed: Please DocuSign - M365info 06/06/2023 12:22`                      FilteredAsSpam
05/06/2023 17.36.04 [email protected]                 [email protected]      Good Day Beloved,                                                            FilteredAsSpam
05/06/2023 14.29.22 [email protected]  [email protected]    Your document has been Completed: Please DocuSign: [email protected]` FilteredAsSpam

注意:Microsoft 的时区采用世界协调时间 (UTC)。例如,中央标准时间 (CST) 比 UTC 晚 5 小时。因此,如果电子邮件在中部标准时间上午 8:00 发送,它将显示为下午 13:00。为了确保获取特定日期范围内的所有邮件以及邮件跟踪,请根据 Exchange 服务器位置和用户邮箱的不同时区添加或减去小时数。

接下来,我们将展示使用 Get-Date PowerShell cmdlet 作为基准并添加 PowerShell 时间单位(例如 AddHoursAddDays)的示例> 和添加分钟

最近 x 分钟内的 Get-MessageTrace 数据

获取有关过去 x 分钟内发送和接收的电子邮件的信息。我们将向您展示过去 30 分钟内发送和接收的所有 Exchange 电子邮件的示例。

运行以下 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddMinutes(-30) -EndDate (Get-Date)

它将获取过去 30 分钟的 Exchange Online 邮件信息。

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddMinutes(-30) -EndDate (Get-Date)

Received            Sender Address              Recipient Address           Subject          Status   
--------            --------------              -----------------           -------          ------   
15/06/2023 19.45.30 [email protected] [email protected]  RE: مرحبا كيف حالك  Delivered
15/06/2023 19.42.43 [email protected]  [email protected] مرحبا كيف حالك      Delivered

注意:您不得超过 10 天的时间限制。当您为 AddMinutes 输入 15840 及以上数字时,会发生错误。

过去 x 小时内的 Get-MessageTrace 数据

获取有关过去 x 小时内发送和接收的电子邮件的信息。该示例将显示过去 30 小时内发送和接收的所有 Exchange 电子邮件。

PowerShell 命令示例:

Get-MessageTrace -StartDate (Get-Date).AddHours(-30) -EndDate (Get-Date)

它将获取过去 30 小时的 Exchange Online 邮件信息。

Powershell 输出示例:

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddHours(-30) -EndDate (Get-Date)

Received            Sender Address              Recipient Address           Subject                                     Status        
--------            --------------              -----------------           -------                                     ------        
15/06/2023 19.45.30 [email protected] [email protected]  RE: مرحبا كيف حالك                             Delivered     
15/06/2023 19.42.43 [email protected]  [email protected] مرحبا كيف حالك                                 Delivered     
15/06/2023 11.54.24 [email protected]           [email protected] If you need paper notebook,Im here for you  FilteredAsSpam

注意:您不能超过 10 天的时间限制,否则会出现错误。将 Addhours 数量保持在 264 以下。

x 天的 Get-MessageTrace 数据

获取有关过去 x 天内发送和接收的电子邮件的信息。您可以显示最近 10 天内发送和接收的所有 Exchange 电子邮件。

运行 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date)

注意:请记住,您不能超过最多 10 天的时间限制。

使用变量的日期范围

如果您想避免输入长且复杂的日期值,可以使用使用变量定义日期范围的方法。

我们定义的变量将包含所需的日期范围。 Get-MessageTrace cmdlet 使用上一步中定义的变量定义日期范围。

使用以下 PowerShell 变量。

$DateEnd = Get-Date
$DateStart = $DateEnd.AddHours(-30)
Get-MessageTrace -StartDate $DateStart -EndDate $DateEnd

PowerShell 输出示例。

PS C:\> $DateEnd = Get-Date
$DateStart = $DateEnd.AddHours(-30)
Get-MessageTrace -StartDate $DateStart -EndDate $DateEnd

Received            Sender Address              Recipient Address           Subject                                     Status        
--------            --------------              -----------------           -------                                     ------        
15/06/2023 19.45.30 [email protected] [email protected]  RE: مرحبا كيف حالك                             Delivered     
15/06/2023 19.42.43 [email protected]  [email protected] مرحبا كيف حالك                                 Delivered     
15/06/2023 11.54.24 [email protected]           [email protected] If you need paper notebook,Im here for you  FilteredAsSpam

Get-MessageTrace 干净结果

当我们在不使用特定筛选器的情况下在 Exchange Online 中使用 Get-MessageTrace PowerShell cmdlet 时,输出会包含有关系统和内部 Exchange Online 邮件消息的不必要信息。

在下面的示例中,我们可以看到与我们的搜索无关的系统电子邮件信息。

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-5) -EndDate (Get-Date)

Received            Sender Address                 Recipient Address              Subject                                                                                          Status        
--------            --------------                 -----------------              -------                                                                                          ------        
15/06/2023 19.45.30 [email protected]    [email protected]     RE: مرحبا كيف حالك                                                                                  Delivered     
15/06/2023 19.42.43 [email protected]     [email protected]    مرحبا كيف حالك                                                                                      Delivered     
15/06/2023 11.54.24 [email protected]              [email protected]    If you need paper notebook,Im here for you                                                       FilteredAsSpam
14/06/2023 11.22.44 [email protected] [email protected]           Your requested Report Amanda is now available                                                    Delivered     
14/06/2023 10.01.30 [email protected]       [email protected]           Get the latest Office apps                                                                       Delivered     
14/06/2023 08.56.40 [email protected]        [email protected] Undeliverable: Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available   Failed        
14/06/2023 08.56.39 [email protected] [email protected]           Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available                  Failed        
14/06/2023 01.57.05 [email protected]    [email protected]    Test your Junk mail!                                                                             FilteredAsSpam
13/06/2023 07.22.03 [email protected]              [email protected]    Professional Notebook manufacturer in China                                                      Delivered     
12/06/2023 20.08.19 [email protected]          [email protected]    Prueba                                                                                           FilteredAsSpam
12/06/2023 14.24.28 [email protected]        [email protected]    spam filter test                                                                                 FilteredAsSpam

假设我们想通过删除有关系统电子邮件的信息来清理搜索结果。在这种情况下,我们将添加过滤器来忽略特定电子邮件。

运行以下 PowerShell 示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-5) -EndDate (Get-Date) | Where {$_.SenderAddress -notlike '*microsoft.com*' -and $_.SenderAddress -notlike '*root' }

在我们的示例中,我们希望删除所有带有 *microsoft.com* 或以 *top 结尾的单词的发件人地址电子邮件

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-5) -EndDate (Get-Date) | Where {$_.SenderAddress -notlike '*microsoft.com*' -and $_.SenderAddress -notlike '*top' }

Received            Sender Address              Recipient Address              Subject                                                                                          Status        
--------            --------------              -----------------              -------                                                                                          ------        
15/06/2023 19.45.30 [email protected] [email protected]     RE: مرحبا كيف حالك                                                                                  Delivered     
15/06/2023 19.42.43 [email protected]  [email protected]    مرحبا كيف حالك                                                                                      Delivered     
14/06/2023 08.56.40 [email protected]     [email protected] Undeliverable: Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available   Failed        
14/06/2023 01.57.05 [email protected] [email protected]    Test your Junk mail!                                                                             FilteredAsSpam
12/06/2023 20.08.19 [email protected]       [email protected]    Prueba                                                                                           FilteredAsSpam
12/06/2023 14.24.28 [email protected]     [email protected]    spam filter test                                                                                 FilteredAsSpam

Get-MessageTrace 与 Group-Object 结果相结合

在某些情况下,我们并不是在查找有关特定电子邮件的信息,而是在查找特定发件人或收件人在特定日期范围内执行的邮件的高级视图。

通过使用 PowerShell cmdlet Group-Object 以及 Get-MessageTrace,我们可以获得电子邮件的高级视图。

注意:Group-Object cmdlet 可帮助我们对有关特定属性的信息进行分组,并使我们能够计算每组中的实例数。

获取有关最活跃组织发件人的信息

在下面的例子中,我们要实现以下需求:

  • 我们希望获取有关过去 10 天内所有发件人发送的电子邮件的信息。
  • 我们希望呈现按每个发送者分组的结果。
  • 我们想要统计每个发件人发送的电子邮件数量。
  • 我们希望按降序顺序显示结果,以便在顶部查看发送最多邮件的用户。

为了获取所需的信息,我们使用执行三项任务的 Group-Object cmdlet:

  • 通过与属性 SenderAddress 相关的方式对结果进行分组。
  • 计算每个发件人的结果(特定发件人发送的邮件项目数)。
  • 按降序排列计数列中显示的信息。

使用 PowerShell 命令组对象语法对最活跃的组织发件人进行排序。

Group-Object -Property SenderAddress | Select Name,Count | Sort Count -Descending

结合 Group-Object 运行 PowerShell 命令示例 Get-MessageTrace

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Group-Object -Property SenderAddress | Select Name,Count | Sort Count -Descending

显示有关从特定发件人(名称)接受的邮件数量(计数)的信息。拥有最多电子邮件的用户将显示在上方。

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Group-Object -Property SenderAddress | Select Name,Count | Sort Count -Descending

Name                                       Count
----                                       -----
[email protected]                         4
[email protected]                    3
[email protected]                     2
[email protected]                 2
[email protected]                              1
[email protected]                       1

获取有关最受欢迎的组织收件人的信息

在下面的示例中,我们希望完成以下要求:

  • 我们希望检索有关我们的用户在过去 10 天内收到(或发送给我们的用户)的每封电子邮件的信息。
  • 我们希望显示按每个收件人 (RecipientAddress) 分组的结果。
  • 我们想要计算每个收件人发送的电子邮件数量
  • 我们希望按降序排列结果。它显示发送最多邮件项目的用户,这些用户是最活跃的收件人。

为了获取所需的信息,我们使用执行三项任务的 Group-Object cmdlet:

  • 按与属性 (RecipientAddress) 相关的方式对结果进行分组。
  • 计算每个收件人的结果(发送给特定收件人的邮件数量)。
  • 按降序排列计数列中显示的信息。

使用 PowerShell 命令组对象语法对最受欢迎的组织收件人进行排序。

Group-Object -Property RecipientAddress | Select Name,Count | Sort Count -Descending

运行 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Group-Object -Property RecipientAddress | Select Name,Count | Sort Count -Descending

它显示收件人(姓名)收到的邮件项目数(计数)。

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Group-Object -Property RecipientAddress | Select Name,Count | Sort Count -Descending

Name                           Count
----                           -----
[email protected]       10
[email protected]         4
[email protected]               3
[email protected]     1
[email protected]             1
[email protected]         1
[email protected]           1
[email protected]            1
[email protected]           1

从特定发件人发送的电子邮件的 Get-MessageTrace

特定发件人是向其他收件人(内部和外部)发送电子邮件的组织用户

使用 PowerShell 参数 -SenderAddress 获取有关特定发件人地址发送的电子邮件的信息。

要检索有关特定发件人发送的电子邮件的信息,您可以使用以下 PowerShell 命令语法。

Get-MessageTrace -SenderAddress <Sender Email address>

PowerShell 命令示例。

Get-MessageTrace -SenderAddress [email protected]

注意:如果您看不到任何结果,则表明该用户在过去 48 小时内没有发送任何电子邮件。默认情况下,Get-MessageTrace 仅显示过去 48 小时的数据。

要获取过去 x 天有关特定发件人的信息,您需要添加参数。

PowerShell 命令语法。

Get-MessageTrace -StartDate (Get-Date).AddDays(-x) -EndDate (Get-Date) -SenderAddress <Sender Email address>

运行以下 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress [email protected]

过去 10 天内特定发件人的 PowerShell 结果。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress [email protected]

Received            Sender Address             Recipient Address           Subject        Status   
--------            --------------             -----------------           -------        ------   
15/06/2023 19.42.43 [email protected] [email protected] مرحبا كيف حالك    Delivered
09/06/2023 09.58.06 [email protected] [email protected] RE: Available  Delivered

您还可以显示特定发件人发送的电子邮件数量。

获取有关特定发件人在过去 x 天内发送的电子邮件数量(计数)的信息。

在此示例中,我们将添加 Group-Object cmdlet 以计算特定发件人发送的电子邮件数量。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress [email protected] | Group-Object -Property SenderAddress | Select Name,Count

PowerShell 结果显示用户发送的电子邮件的计数。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress [email protected] | Group-Object -Property SenderAddress | Select Name,Count

Name                       Count
----                       -----
[email protected]     2

获取过去 x 天内由多个发件人(其电子邮件地址包含特定域名)发送的电子邮件的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate (Get-Date).AddDays(-x) -EndDate (Get-Date) -SenderAddress <*@Domain name>

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress *@a-d.site

我们的示例显示过去 10 天内由具有相同域名 (a-d.site) 的发件人发送的所有电子邮件的信息。

PowerShell 输出结果。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -SenderAddress *@a-d.site

Received            Sender Address              Recipient Address              Subject                                                                                          Status   
--------            --------------              -----------------              -------                                                                                          ------   
15/06/2023 19.45.30 [email protected] [email protected]     RE: مرحبا كيف حالك                                                                                  Delivered
15/06/2023 19.42.43 [email protected]  [email protected]    مرحبا كيف حالك                                                                                      Delivered
14/06/2023 08.56.40 [email protected]     [email protected] Undeliverable: Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available   Failed   
09/06/2023 10.01.37 [email protected] [email protected]         Test                                                                                             Delivered
09/06/2023 09.58.06 [email protected]  [email protected]    RE: Available                                                                                    Delivered
09/06/2023 09.56.06 [email protected] [email protected]     Available                                                                                        Delivered

将发件人发送的电子邮件信息导出为 CSV

将有关从特定发件人发送的电子邮件的信息导出到文件。您可以为每个发件人创建专用文件。

您可以获得有关 Exchange Online 中显示的每个发件人执行的所有邮件的信息。

我们需要满足的要求包括以下几个部分:

  • 显示有关过去 10 天内发送电子邮件的所有发件人的信息。
  • 它将信息保存并导出到 CSV(逗号分隔值)文件。
  • 它将为每个发件人创建并导出专用的 CSV 文件。例如,如果发件人是 [email protected],则为“Amanda”创建的专用 CSV 文件将仅包含从 [email protected] 发送的电子邮件的信息。

为了获取所需的信息,我们将使用 PowerShell ForEach 语句:

  • 在第一阶段,ForEach 语句将循环访问 Exchange Online 中的记录数组。
  • 在第二阶段,我们根据发件人身份将所需信息导出到单独的 CSV 文件。

PowerShell 命令示例。

$AllSender = Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Group-Object -Property SenderAddress | Select Name
$AllSender = $AllSender.name
$ErrorActionPreference = "SilentlyContinue"
ForEach ($Sender in $AllSender) {
    Get-MessageTrace -StartDate (Get-Date).AddDays(-3) -EndDate (Get-Date) -SenderAddress $Sender | Export-Csv "C:\temp$sender.csv" -NoTypeInformation -Encoding UTF8
}

发送给特定收件人的电子邮件的 Get-MessageTrace

-RecipientAddress 参数可让我们获取有关发送给特定收件人的电子邮件的信息。

我们想要展示如何获取有关发送给组织收件人的(内部和外部)电子邮件的信息。

请参阅下面的 PowerShell 语法。

Get-MessageTrace -RecipientAddress <Recipient Email Address>

运行以下 PowerShell 命令示例。

Get-MessageTrace -RecipientAddress [email protected]

注意:如果您看不到任何结果,则说明过去 48 小时内没有向该收件人用户发送任何电子邮件。默认情况下,Get-MessageTrace 仅显示过去 48 小时的数据。

您还可以查看过去 x 天内发送给特定组织收件人的电子邮件的信息。但您需要添加参数-StartDate-EndDate

PowerShell 命令语法。

Get-MessageTrace -StartDate (Get-Date).AddDays(-x) -EndDate (Get-Date) -RecipientAddress <Recipient Email Address>

运行 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress [email protected]

过去 10 天内发送给特定组织收件人的电子邮件的 PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress [email protected]

Received            Sender Address                    Recipient Address          Subject                                                Status        
--------            --------------                    -----------------          -------                                                ------        
15/06/2023 19.45.30 [email protected]       [email protected] RE: مرحبا كيف حالك                                        Delivered     
09/06/2023 10.13.47 [email protected]            [email protected] This is a test                                         Delivered     
09/06/2023 09.56.06 [email protected]       [email protected] Available                                              Delivered     
07/06/2023 06.55.21 [email protected] [email protected] All parties have Completed: Please DocuSign: M365info` FilteredAsSpam

显示有关过去 x 天内发送给特定收件人的电子邮件的附加信息,并计算电子邮件的数量。

在此示例中,我们将添加 Group-Object cmdlet 以计算发送给特定收件人的电子邮件数量。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress [email protected] | Group-Object -Property SenderAddress | Select Name,Count

PowerShell 输出显示一个列表,其中包含电子邮件发件人(名称)以及发送给收件人 ([email protected]) 的电子邮件数量(计数)。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress [email protected] | Group-Object -Property SenderAddress | Select Name,Count

Name                              Count
----                              -----
[email protected]           2
[email protected]                1
[email protected]     1

查看过去 x 天内发送给特定收件人(其电子邮件地址中包含特定域名)的电子邮件的信息。

PowerShell 命令语法

Get-MessageTrace -StartDate (Get-Date).AddDays(-x) -EndDate (Get-Date) -RecipientAddress <*@Domain Name>

在以下示例中,我们希望获取过去 10 天内发送给所有具有电子邮件地址的收件人的电子邮件的信息,包括域名 (a-d.site)。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress *@a-d.site

我们的示例显示过去 10 天内发送给具有相同域名 (a-d.site) 的收件人的所有电子邮件。

PowerShell 输出示例。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -RecipientAddress *@a-d.site

Received            Sender Address                             Recipient Address           Subject                                                                           Status        
--------            --------------                             -----------------           -------                                                                           ------        
15/06/2023 19.45.30 [email protected]                [email protected]  RE: مرحبا كيف حالك                                                                   Delivered     
15/06/2023 19.42.43 [email protected]                 [email protected] مرحبا كيف حالك                                                                       Delivered     
15/06/2023 11.54.24 [email protected]                          [email protected] If you need paper notebook,Im here for you                                        FilteredAsSpam
14/06/2023 11.22.44 [email protected]             [email protected]        Your requested Report Amanda is now available                                     Delivered     
14/06/2023 10.01.30 [email protected]                   [email protected]        Get the latest Office apps                                                        Delivered     
14/06/2023 08.56.39 [email protected]             [email protected]        Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available   Failed        
14/06/2023 01.57.05 [email protected]                [email protected] Test your Junk mail!                                                              FilteredAsSpam
13/06/2023 07.22.03 [email protected]                          [email protected] Professional Notebook manufacturer in China                                       Delivered     
12/06/2023 20.08.19 [email protected]                      [email protected] Prueba                                                                            FilteredAsSpam
12/06/2023 14.24.28 [email protected]                    [email protected] spam filter test                                                                  FilteredAsSpam
09/06/2023 10.13.47 [email protected]                     [email protected]  This is a test                                                                    Delivered     
09/06/2023 10.04.16 [email protected]                     [email protected] Re: Test                                                                          Delivered     
09/06/2023 09.58.06 [email protected]                 [email protected] RE: Available                                                                     Delivered     
09/06/2023 09.56.06 [email protected]                [email protected]  Available                                                                         Delivered     
07/06/2023 21.15.32 [email protected]          [email protected]  All parties have Completed: Please DocuSign`M365info                              FilteredAsSpam
07/06/2023 12.32.00 [email protected]           [email protected]    All parties have Completed: Please DocuSign:`[email protected]             FilteredAsSpam
07/06/2023 06.55.21 [email protected]          [email protected]  All parties have Completed: Please DocuSign: M365info`                            FilteredAsSpam
06/06/2023 21.30.03 [email protected] [email protected]     Approved: Completed: Please DocuSign: M365info`                                   FilteredAsSpam
06/06/2023 20.34.22 [email protected]                     [email protected] Test your Junk mail!                                                              FilteredAsSpam
06/06/2023 20.25.41 [email protected]                     [email protected] Just a test!                                                                      Delivered     
06/06/2023 19.22.32 [email protected] [email protected]    Completed: Please DocuSign - M365info 06/06/2023 12:22`                           FilteredAsSpam

具有特定状态的电子邮件的 Get-MessageTrace

参数-Status按电子邮件的传递状态过滤结果。该参数的有效值为:

  • :邮件没有送达状态,因为它被拒绝或重定向到其他收件人。
  • 失败:尝试传递邮件但失败,或者邮件被作为垃圾邮件或恶意软件过滤,或者被传输规则过滤。
  • 待处理:消息传送正在进行或被推迟并正在重试。
  • 已送达:邮件已送达目的地。
  • 扩展:没有邮件传递,因为邮件被发送到通讯组,并且通讯组的成员资格已扩展。

获取有关具有特定状态的已发送或已接收电子邮件的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -Status <Status>

获取有关过去 x 天内发送或接收的具有特定状态的电子邮件的信息

PowerShell 命令语法

Get-MessageTrace -StartDate (Get-Date).AddDays(-x) -EndDate (Get-Date) -Status <Status>

在以下示例中,我们希望获取有关过去 10 天内 -Status 值“失败”的传入和传出电子邮件的信息。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -Status Failed

我们可以使用另一种可选语法来获取有关具有特定状态的电子邮件的信息。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Where {$_.Status -eq "Failed"}

PowerShell 输出显示状态失败的所有电子邮件。

PS C:\Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Where {$_.Status -eq "Failed"}

Received            Sender Address                 Recipient Address              Subject                                                                                          Status
--------            --------------                 -----------------              -------                                                                                          ------
14/06/2023 08.56.40 [email protected]        [email protected] Undeliverable: Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available   Failed
14/06/2023 08.56.39 [email protected] [email protected]           Your requested Message trace report - ‎2023-06-14T08:25:07.136Z‎ is now available                  Failed

将具有特定状态的电子邮件信息导出到 CSV

您可以获得有关过去 10 天内发送和接收的所有电子邮件的状态的信息。为每种状态类型创建单独的 CSV 文件。

我们需要满足的要求包括以下几个部分:

  • 它将我们从 Get-MessageTrace 命令获取的信息保存并导出到 CSV(逗号分隔值)文件。
  • 它将为每种类型的状态导出一个单独的 CSV 文件; 已交付已扩展失败待处理

为了满足此要求,我们将使用 PowerShell ForEach 语句。

  • 在第一阶段,ForEach 语句将循环访问 Exchange Online 中的记录数组。
  • 在第二阶段,我们根据具体的邮件状态将所需信息导出到单独的CSV文件中。

PowerShell 命令示例。

$statuses = "None", "Failed", "Pending", "Delivered", "Expanded"
ForEach ($status in $statuses) {
    Get-MessageTrace -StartDate (Get-Date).Adddays(-10) -EndDate (Get-Date) -Status $status | Export-Csv "C:\temp$status.csv" -NoTypeInformation -Encoding UTF8
}

注意:如果没有特定状态的电子邮件,它将导出一个空的 CSV 文件。

显示有关发送到通讯组的邮件数量的信息

在此示例中,我们想要获取有关发送到通讯组的电子邮件地址的信息。在查找通讯组时,我们使用特定状态已扩展。每当电子邮件发送到通讯组时,Exchange 都会执行展开操作。因此,我们将对结果进行分组,然后对结果进行计数

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -Status Expanded | Group-Object -Property RecipientAddress | Select Name,Count | Sort Count -Descending

注意:如果已扩展状态下不存在任何数据,则 PowerShell 输出将不显示任何内容。

具有特定主题的电子邮件的 Get-MessageTrace

Get-MessageTrace 变量 $Subject 使我们能够获取有关包含特定主题或邮件主题中特定字符串的电子邮件的信息。

让我们获取过去 x 天内发送和接收的特定主题电子邮件的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> | Where {$_.Subject -like "*<string>*"}

运行以下 PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Where {$_.Subject -like "*test*"}

我们的 PowerShell 输出示例显示过去 10 天内主题词为 *test* 的所有电子邮件。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Where {$_.Subject -like "*test*"}

Received            Sender Address              Recipient Address           Subject                    Status        
--------            --------------              -----------------           -------                    ------        
14/06/2023 10.01.30 [email protected]    [email protected]        Get the latest Office apps Delivered     
14/06/2023 01.57.05 [email protected] [email protected] Test your Junk mail!       FilteredAsSpam
12/06/2023 14.24.28 [email protected]     [email protected] spam filter test           FilteredAsSpam
09/06/2023 10.13.47 [email protected]      [email protected]  This is a test             Delivered     
09/06/2023 10.04.16 [email protected]      [email protected] Re: Test                   Delivered     
09/06/2023 10.01.37 [email protected] [email protected]      Test                       Delivered     
06/06/2023 20.34.22 [email protected]      [email protected] Test your Junk mail!       FilteredAsSpam
06/06/2023 20.25.41 [email protected]      [email protected] Just a test!               Delivered     

Get-MessageTrace 按源或目标 IP 地址过滤结果

IP地址是代表特定域名或特定收件人的邮件服务器的公共IP地址。

Get-MessageTrace 参数 -ToIP-FromIP 允许我们检索有关从特定 IP 地址发送或发送到特定 IP 地址的电子邮件的信息。

首先,我们将使用参数-ToIP,它与邮件服务器Exchange Online 的IP 地址相关。

ToIP

ToIP 参数按目标 IP 地址过滤结果。对于传出邮件,ToIP 的值是目标域的已解析 MX 记录中的公共 IP 地址。对于 Exchange Online 的传入邮件,该值为空。

FromIP

FromIP 参数按源 IP 地址过滤结果。对于传入邮件,FromIP 的值是发送邮件的 SMTP 电子邮件服务器的公共 IP 地址。

ToIP - 获取有关发送到具有特定 IP 地址的目标邮件服务器的电子邮件的信息

获取有关发送到具有特定 IP 地址的邮件服务器的电子邮件的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -ToIP <IP address>

在以下示例中,我们希望获取过去 10 天内发送到 IP 地址为 10.0.0.2 的目标邮件服务器的邮件项目的信息。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) -ToIP 10.0.0.2

FromIP - 获取有关从特定 IP 地址发送的电子邮件的信息

Get-MessageTrace 参数 -FromIP 允许我们检索有关从特定 IP 地址发送的电子邮件的信息。

检索有关从具有特定 IP 地址的邮件服务器收到的电子邮件的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -FromIP <IP address>

在下面的示例中,我们希望获取 IP 地址为 10.0.0.2 的邮件服务器在过去 10 天内发送的邮件信息。

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).Adddays(-10) -EndDate (Get-Date) -FromIP 10.0.0.2

PowerShell 输出结果。

PS C:\> Get-MessageTrace -StartDate (Get-Date).Adddays(-10) -EndDate (Get-Date) -FromIP 80.71.142.100

Received            Sender Address              Recipient Address           Subject            Status   
--------            --------------              -----------------           -------            ------   
15/06/2023 19.45.30 [email protected] [email protected]  RE: مرحبا كيف حالك    Delivered
15/06/2023 19.42.43 [email protected]  [email protected] مرحبا كيف حالك        Delivered
09/06/2023 10.01.37 [email protected] [email protected]      Test               Delivered
09/06/2023 09.58.06 [email protected]  [email protected] RE: Available      Delivered
09/06/2023 09.56.06 [email protected] [email protected]  Available          Delivered

扩展 Page 或 PageSize 数字结果

使用 PowerShell 命令 Get-MessageTrace 显示信息时,邮件数量存在内置限制。指定显示结果限制的单位称为页面

注意: 默认情况下,Get-MessageTrace 将仅显示 1 页。默认情况下,每个页面单元包含 1,000 行。

默认情况下,即使搜索结果包含超过 1,000 行,Get-MessageTrace 命令也将最多显示 1,000 个结果。因此我们需要使用一个参数来帮助我们获得更多的结果。

Get-MessageTrace 包括两个与最大显示结果主题相关的参数:

Page

Page 参数指定要查看的结果的页码。此参数的有效输入是 1 到 1000 之间的整数。默认值为 1。

PageSize

PageSize 参数指定每页的最大条目数。此参数的有效输入是 1 到 5000 之间的整数。默认值为 1000。

扩展默认页面大小限制

将 PageSize 限制扩展到 5,000 的一种方法。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -PageSize <number or records that each page includes>

PowerShell 命令示例。

Get-MessageTrace -StartDate (Get-Date).Adddays(-10) -EndDate (Get-Date) -PageSize 5000

如果您有 20 页,则可以使用 PowerShell 获取有关特定页码的信息。

PowerShell 命令语法。

Get-MessageTrace -StartDate <mm/dd/yyyy> -EndDate <mm/dd/yyyy> -Page <page number>

运行PowerShell命令示例查看第5页的信息。

Get-MessageTrace -StartDate (Get-Date).Adddays(-10) -EndDate (Get-Date) -Page 5

对特定邮件使用 MessageTraceDetail

如前所述,Get-MessageTrace cmdlet 为我们提供了有关特定邮件的基本信息。

如果我们想要有关特定邮件的更多详细信息,我们可以添加 PowerShell 命令 Get-MessageTraceDetail。

我们将把 MessageTraceDetail cmdlet 添加到原始的 Get-MessageTrace 命令中。

注意:使用Get-MessageTraceDetail cmdlet 查看特定消息的消息跟踪事件详细信息。这些详细结果比 Get-MessageTrace 结果需要更多时间。

获取过去 3 天内所有发送和接收的电子邮件的邮件详细信息。

PowerShell 命令示例:

Get-MessageTrace -StartDate (Get-Date).AddDays(-3) -EndDate (Get-Date) | Get-MessageTraceDetail

您必须等待几分钟才能在 PowerShell 控制台上看到结果。

PowerShell 输出结果。

PS C:\> Get-MessageTrace -StartDate (Get-Date).AddDays(-3) -EndDate (Get-Date) | Get-MessageTraceDetail

Date                   Event                Detail                                                                                                                                                   
----                   -----                ------                                                                                                                                                   
15/06/2023 11.54.24    Receive (with ext... Message received by: DU0PR02MB8289.eurprd02.prod.outlook.com. There was a delay of 1907 minutes prior to the message being received by Office 365.       
15/06/2023 11.54.26    Spam                 No detail information available.                                                                                                                         
15/06/2023 11.54.27    Deliver              The message was delivered to the Junk Email folder.                                                                                                      
14/06/2023 11.22.44    Receive              Message received by: DB3PR0202MB9154.eurprd02.prod.outlook.com using TLS1.2 with AES256                                                                  
14/06/2023 11.22.45    Deliver              The message was successfully delivered.                                                                                                                  
14/06/2023 10.01.31    Receive              Message received by: DU0PR02MB8716.eurprd02.prod.outlook.com using TLS1.2 with AES256                                                                    
14/06/2023 10.01.33    Deliver              The message was successfully delivered.                                                                                                                  
14/06/2023 08.56.41    Drop                 Reason: [{LED=550 4.3.2 QUEUE.TransportAgent; message deleted by transport agent};{MSG=};{FQDN=};{IP=};{LRT=}]                                           
14/06/2023 08.56.39    Receive              Message received by: AS2PR02MB10153.eurprd02.prod.outlook.com using TLS1.2 with AES256                                                                   
14/06/2023 08.56.40    Fail                 Reason: [{LED=550 5.1.10 RESOLVER.ADR.RecipientNotFound; Recipient [email protected] not found by SMTP address lookup};{MSG=};{FQDN=};{IP=};{LRT=}]   
14/06/2023 01.57.06    Receive              Message received by: DU0PR02MB8039.eurprd02.prod.outlook.com using TLS1.2 with AES256                                                                    
14/06/2023 01.57.07    Spam                 No detail information available.                                                                                                                         
14/06/2023 01.57.08    Deliver              The message was delivered to the Junk Email folder.                                                                                                      
13/06/2023 07.22.04    Receive              Message received by: GV1PR02MB7779.eurprd02.prod.outlook.com                                                                                             
13/06/2023 07.22.08    Deliver              The message was successfully delivered.                                                                                                                  

接下来,我们将向您展示如何将 PowerShell 信息导出到文件。

将 Get-MessageTrace 结果导出到文件

您还可以将信息导出为 PowerShell 支持的文件格式。 PowerShell 支持将输出导出为以下文件格式:文本、CSV、HTML 和 XML。

当我们将命令输出导出到文件时,我们需要告诉PowerShell我们想要的格式。

除了用于定义特定文件格式的 PowerShell cmdlet 之外,我们还可以添加与特定文件格式相关的特定参数。

例如,当我们希望将 PowerShell 命令输出导出为 CSV(逗号分隔值)文件格式时,我们可以添加其他参数,例如:

-NoTypeInformation

防止向 CSV 文件添加不必要的信息。

-Encoding UTF8

它确保用户或邮箱中包含的非英语字符可以跨支持 UTF-8 编码的不同系统、应用程序和编程语言导出

1.创建文件名和路径

需要为使用 PowerShell 导出的文件命名。附加部分是选择目录路径。路径参数定义我们要保存文件的位置,例如C:\temp

然而,路径参数不是强制性的。如果我们不提供特定路径,PowerShell 会将文件导出到我们运行 PowerShell 命令的文件夹。

注意:默认情况下,PowerShell 命令不会创建路径中指定的特定文件夹。

2.导出为文件类型格式

我们将展示将信息导出到各种文件类型的 PowerShell 语法。

要将信息导出为 PowerShell 中的文件格式,您需要以下两个部分:

  1. 键入获取特定信息的 Get PowerShell cmdlet。
  2. 定义特定的文件格式、路径和文件名。

查看下面的 PowerShell 示例,以三种文件格式导出信息; 文本CSVHTML

将信息导出到文本文件

PowerShell 命令示例

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Out-File "C:\Temp\All emails in the last month.TXT"

将信息导出到 CSV 文件

PowerShell 命令示例

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | Export-CSV "C:\Temp\All emails in the last month.CSV" -NoTypeInformation -Encoding UTF8

将信息导出到 HTML 文件

PowerShell 命令示例

Get-MessageTrace -StartDate (Get-Date).AddDays(-10) -EndDate (Get-Date) | ConvertTo-Html | Out-File "C:\Temp\All emails in the last month.HTML"

了解更多:在 Microsoft 365 中配置捕获所有邮箱 »

结论

您了解了如何使用 Get-MessageTrace PowerShell cmdlet 查看最多 10 天前的 Exchange Online 邮件。这是从某个时间范围收集特定数据并将其导出到 csv 文件的绝佳方法。

您喜欢这篇文章吗?您可能还喜欢启用或禁用 Exchange ActiveSync 邮箱。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯