Entra / Microsoft 365 · Compliance & audit
Get Copilot audit records
Search the unified audit log for Copilot for Microsoft 365 interaction records and report activity by user and Copilot app host.
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 = 180)[array]$Modules = Get-Module | Select-Object -ExpandProperty NameIf ($Modules -notcontains "ExchangeOnlineManagement") {Write-Host "Connecting to Microsoft Teams..."Connect-ExchangeOnline -ShowBanner:$False}[array]$Records = Search-UnifiedAuditLog –StartDate (Get-Date).AddDays(-$LookbackDays) –EndDate (Get-Date).AddDays(1) –ResultSize 5000 –SessionCommand ReturnLargeSet -Formatted -Operations 'CopilotInteraction'$Records = $Records | Sort-object Identity -Unique | Sort-Object {$_.CreationDate -as [DateTime]}$Records | Group-Object userids -NoElement | Sort-Object Count -Descending | Format-Table Name, Count$Report = [System.Collections.Generic.List[Object]]::new()ForEach ($Rec in $Records) {$MsgCount = 0$AuditData = $Rec.AuditData | ConvertFrom-JsonSwitch ($Auditdata.CopilotEventData.AppHost) {"Outlook" {$MsgCount = $AuditData.CopilotEventData.AccessedResources.Count}"Word" {$MsgCount = $Auditdata.CopilotEventData.Contexts.Id.count}}$ReportLine = [pscustomobject]@{User = $Rec.UserIdsCreationDate = $Rec.CreationDate'Copilot App' = $Auditdata.CopilotEventData.AppHostContext = $AuditData.CopilotEventData.Contexts.IdFileType = $AuditData.CopilotEventData.Contexts.TypePrompt = $AuditData.CopilotEventData.Messages.IsPromptThreadId = $AuditData.CopilotEventData.Messages.IdItemCount = $MsgCount}$Report.Add($ReportLine)}
Parameters
ParameterDefaultNotes
-LookbackDays180Number of days to search the unified audit log for CopilotInteraction operations.Attribution
Author
Office365itpros