Office 365 Reporting Web Service を簡単に試す方法はありませんが、PowerShell を使用することで比較的簡単に動作を確認できます。紹介するのはメッセージ追跡ログの取得方法のみですが、同じ要領で他のレポートも取得できます。
PowerShell で試す
- Windows PowerShell を起動します。
- 以下のようにコマンドを実行します。認証ダイアログが表示されたら Office 365 の管理者の資格情報を入力してください。ここでは検索条件として差出人のメール アドレスを指定しているので、適宜変更してください。
$Credential = Get-Credential
(Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/?`$filter=SenderAddress eq 'User01@contoso.onmicrosoft.com'" -Credential $Credential).content.properties | select @{n="Received"; e={$_.Received."#text".Split('.')[0]}}, SenderAddress, RecipientAddress,Subject,Status | ft
- 実行結果として、Get-MessageTrace コマンド相当の内容が取得できたことを確認します。
- 日付を指定するには以下のようにコマンドを実行します。
(Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/?`$filter=StartDate eq datetime'2019-07-18T00:00:00Z' and EndDate eq datetime'2019-07-19T00:00:00Z'" -Credential $Credential).content.properties | select @{n="Received"; e={$_.Received."#text".Split('.')[0]}}, SenderAddress, RecipientAddress,Subject,Status | ft
- Get-MessageTraceDetail コマンド相当の内容を取得するには、改めリクエストを作成する必要があります。以下のコマンドを実行して、URL 生成関数を定義します。
function Get-MessageTraceDetailUrl {
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[System.Xml.XmlLinkedNode]$MessageTraceEntry,
[switch]$Escape
)
$MessageTraceId = $MessageTraceEntry.MessageTraceId.InnerText
$RecipientAddress = $MessageTraceEntry.RecipientAddress
$SenderAddress = $MessageTraceEntry.SenderAddress
$StartDate = $MessageTraceEntry.StartDate.InnerText
$EndDate = $MessageTraceEntry.EndDate.InnerText
$URL = "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTraceDetail?`$filter=MessageTraceId eq guid'$MessageTraceId' and RecipientAddress eq '$RecipientAddress' and SenderAddress eq '$SenderAddress' and StartDate eq datetime'$StartDate' and EndDate eq datetime'$EndDate'"
if ($Escape) {
$URL = $URL.Replace("`$", "``$")
}
$URL | clip
Write-Host "URL was copied to your clipboard."
return $URL
}
- まずは Get-MessageTrace コマンド相当のログを変数に格納します。以下のようにコマンドを実行します。
$MessageTrace = Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/" -Credential $Credential
- 以下のようにコマンドを実行して、Get-MessageTrace コマンドのログの 1 件目のメッセージに対する Get-MessageTraceDetail コマンド相当のリクエストの URL を生成します。
$MessageTrace.Content.Properties[0] | Get-MessageTraceDetailUrl -Escape
- 生成した URL を使用して、以下のようにコマンドを実行します。
(Invoke-RestMethod "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTraceDetail?`$filter=MessageTraceId eq guid'e020bee3-7367-434d-c438-08d70c2fe364' and RecipientAddress eq 'user01@contoso.com' and SenderAddress eq 'user01@fabrikam.com' and StartDate eq datetime'2019-07-17T10:04:41.9725449Z' and EndDate eq datetime'2019-07-19T10:04:41.9725449Z'" -Credential $Credential).Content.Properties | select @{n="Date"; e={$_.Date.InnerText}}, Event, @{n="Detail"; e={if ($_.Detail.GetType().Name -eq "String") {$_.Detail} else {""}}}
- Get-MessageTraceDetail 相当の内容が取得できたことを確認します。