Office 365에서 SMTP 로그를 내보낼 수 있습니까? 어쩌면 powershell 또는 다른 방법으로도 가능합니다.
내 목표는 특정 도메인과주고받는 모든 메시지에 대한 전체 개요를 갖는 것입니다.
답변
온라인 어딘가에있는 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
답변
모든 로그를 수집하기 위해 몇 줄을 약간 변경했습니다.
$OutputFile = "c:\temp\SMTPlog"
$CurrMessages | Export-Csv "$($OutputFile)$($Page).csv" -NoTypeInformation