如何在Office 365中导出完整的SMTP日志


10

在Office 365中,是否可以导出SMTP日志?可能是通过powershell或其他任何方式。

我的目标是全面了解从特定域发送或发送到特定域的所有邮件。


a complete overview of all messages send from and to a specific domain 您知道,当您进入“云”时,通常会放弃这种东西。如果您需要/想要这种全面的监视和日志记录,也许云服务并不是您真正想要的。
HopelessN00b 2014年

3
您认为HopelessN00b还有更多Office365。:-)
ZEDA-NL 2014年

Answers:


12

通过结合在网上某个地方找到的2个脚本,我设法弄清楚了。

这是完成任务的脚本。

#Accept input parameters 
Param( 
    [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 
    [string] $Office365Username, 
    [Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$true)] 
    [string] $Office365Password 
) 

$OutputFile = "DetailedMessageStats.csv" 

Write-Host "Connecting to Office 365 as $Office365Username..." 

#Connect to Office 365 
$SecurePassword = $Office365Password | ConvertTo-SecureString -AsPlainText -Force 
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Office365Username, $SecurePassword 
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection  
Import-PSSession $session -AllowClobber 

Write-Host "Collecting Recipients..." 

#Collect all recipients from Office 365 
$Recipients = Get-Recipient -ResultSize Unlimited | select PrimarySMTPAddress 
$MailTraffic = @{} 
foreach($Recipient in $Recipients) 
{ 
    $MailTraffic[$Recipient.PrimarySMTPAddress.ToLower()] = @{} 
} 
$Recipients = $null 

#Collect Message Tracking Logs (These are broken into "pages" in Office 365 so we need to collect them all with a loop) 
$Messages = $null 
$Page = 1 
do 
{ 

    Write-Host "Collecting Message Tracking - Page $Page..." 
    $CurrMessages = Get-MessageTrace -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date)  -PageSize 5000  -Page $Page| Select Received,*Address,*IP,Subject,Status,Size

    if ($CurrMessages -ne $null)
      {
      $CurrMessages | Export-Csv C:\FILE-$PAGE.csv -NoTypeInformation
      }
    $Page++ 
    $Messages += $CurrMessages 


} 
until ($CurrMessages -eq $null) 

Remove-PSSession $session 

很棒的脚本!我必须修改URL才能连接到我的Office 365实例。我使用了使用远程PowerShell连接到Exchange Online上的信息来处理连接,而其余脚本则获取了文件。
杰森·梅西

-1

我对几行做了些微改动,以收集所有日志

$OutputFile = "c:\temp\SMTPlog"

$CurrMessages | Export-Csv "$($OutputFile)$($Page).csv" -NoTypeInformation

3
嗨,我怀疑您想编辑答案以添加详细信息或在其他答案上留下评论,如果您打算将其保留为答案,建议您将整个脚本粘贴您的更改并留下一个基于其的注释在另一个答案上,因此它将是一个完整的答案。
yagmoth555
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.