Entra / Microsoft 365 · Compliance & audit
Report send as audit events
Example used in Chapter 20 of Office 365 for IT Pros to illustrate how to find and report SendAs audit events.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnline -ShowBanner:$false
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
param([int] $LookbackDays = 90)CLSWrite-Host "Populating Recipients Table..."$RecipientsTable = @{}Try {$Recipients = Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox, SharedMailbox}Catch {Write-Host "Can't find recipients" ; break}# Now Populate hash table with recipient data$Recipients.ForEach( {$RecipientsTable.Add([String]$_.PrimarySmtpAddress, $_.RecipientTypeDetails) } )# And include group mailboxes$GroupMailboxes = Get-Mailbox -ResultSize Unlimited -GroupMailbox$GroupMailboxes.ForEach( {$RecipientsTable.Add([String]$_.PrimarySmtpAddress, $_.RecipientTypeDetails) } )Write-Host "Finding audit records for Send As operations..."$Records = (Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-$LookbackDays) -EndDate (Get-Date).AddDays(+1) -Operations "SendAs" -ResultSize 1000)If ($Records.Count -eq 0) {Write-Host "No audit records for Send As found." }Else {Write-Host "Processing" $Records.Count "Send As audit records..."$Report = [System.Collections.Generic.List[Object]]::new() # Create output file# Scan each audit record to extract informationForEach ($Rec in $Records) {$AuditData = ConvertFrom-Json $Rec.Auditdata$MailboxType = $RecipientsTable.Item($AuditData.MailboxOwnerUPN) # Look up hash tableIf ($MailboxType -eq "GroupMailbox") {$Reason = "Group Mailbox Send"} Else {$Reason = "Delegate Send As"}If ($AuditData.UserId -eq "S-1-5-18") {$UserId = "Service Account"} Else {$UserId = $AuditData.UserId}$ReportLine = [PSCustomObject] @{TimeStamp = Get-Date($AuditData.CreationTime) -format gSentBy = $AuditData.MailboxOwnerUPNSentAs = $AuditData.SendAsUserSmtpSubject = $AuditData.Item.SubjectUser = $AuditData.UserIdAction = $AuditData.OperationReason = $ReasonUserType = $AuditData.UserTypeLogonType = $AuditData.LogonTypeClientIP = $AuditData.ClientIPMailboxType = $MailboxTypeClientInfo = $AuditData.ClientInfoStringStatus = $AuditData.ResultStatus }$Report.Add($ReportLine) }}$Report | ? {$_.MailboxType -eq "UserMailbox"}"} | Out-GridView
Parameters
ParameterDefaultNotes
-LookbackDays90Number of days back to search the unified audit log.Attribution
Author
Office365itpros