Back to script library
Entra / Microsoft 365 · Compliance & audit

Find Send As audit records

Find Send As records in the Microsoft 365 audit log and identify events belonging to user and shared mailboxes versus group mailboxes and Teams.

Connect & set up

Run these once per session. All scopes are read-only unless the script makes changes.

Connect-ExchangeOnline -SkipLoadingCmdletHelp

Run it

The main script. Copy it, or download the .ps1 and run it from your console.

param(
[int] $LookbackDays = 90
)
CLS
Write-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 label 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..."
# You might need to increase the number of retrieved records if your tenant generates lots of SendAs events
$Records = (Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-$LookbackDays) -EndDate (Get-Date).AddDays(+1) -Operations "SendAs" -ResultSize 2000)
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 information
ForEach ($Rec in $Records) {
$AuditData = ConvertFrom-Json $Rec.Auditdata
$MailboxType = $RecipientsTable.Item($AuditData.MailboxOwnerUPN) # Look up hash table
If ($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 g
SentBy = $AuditData.MailboxOwnerUPN
SentAs = $AuditData.SendAsUserSmtp
Subject = $AuditData.Item.Subject
User = $AuditData.UserId
Action = $AuditData.Operation
Reason = $Reason
UserType = $AuditData.UserType
LogonType = $AuditData.LogonType
ClientIP = $AuditData.ClientIP
MailboxType = $MailboxType
ClientInfo = $AuditData.ClientInfoString
Status = $AuditData.ResultStatus }
$Report.Add($ReportLine) }
}
$Report | ? {$_.MailboxType -eq "UserMailbox"} | Out-GridView
$Report | Export-Csv -NoTypeInformation -Path c:\temp\SendASAuditRecords.csv
Write-Host "Report File saved in" c:\temp\SendASAuditRecords.csv

Parameters

ParameterDefaultNotes
-LookbackDays90Number of days to search the unified audit log for Send As operations.
Attribution