Understanding what users search across Microsoft 365 (SharePoint, OneDrive, Teams) can unlock powerful insights—from improving content discovery to preparing your environment for Copilot.
However, Microsoft 365 does not provide an easy built-in report for search queries—and more importantly, this capability is not available in all licenses.
In this guide, you’ll learn how to track and export Microsoft 365 search activity using Microsoft Graph PowerShell, along with licensing requirements, working scripts, use cases, and troubleshooting.
By the end of this article, you’ll be able to:
Install-Module Microsoft.Graph -Scope CurrentUser
You’ll need (Admin Consent required):
Before proceeding, it’s important to understand that search query tracking depends on Microsoft 365 licensing.
The SearchQueryPerformed audit event is only available in advanced auditing scenarios, typically under:
✅ Supported Licenses
❌ Not Available In
Microsoft splits audit logging into two tiers:
| Audit Type | Included In | Capability |
| Audit (Standard) | E3 / Business | Basic activity logs |
| Audit (Premium) | E5 | Advanced telemetry (including search queries) |
The SearchQueryPerformed event is part of Audit Premium, which includes:
Run:
Get-MgAuditLogDirectoryAudit -Top 10 | Select-Object ActivityDisplayName
If you do not see:
SearchQueryPerformed
👉 Your tenant likely does not have Audit Premium enabled
Even with E5:
If you're on E3 or Business plans, you can still:
👉 But direct search query tracking is not available
Connect-MgGraph -Scopes "AuditLog.Read.All","Reports.Read.All","Sites.Read.All"
⚠️ Important: The following script works only if your tenant supports the SearchQueryPerformed event (see licensing section above).
# Define date range
$StartDate = (Get-Date).AddDays(-7)
$EndDate = Get-Date
# Fetch audit logs related to search
$SearchLogs = Get-MgAuditLogDirectoryAudit -Filter "activityDisplayName eq 'SearchQueryPerformed'" -All
# Filter by date range
$FilteredLogs = $SearchLogs | Where-Object {
$_.ActivityDateTime -ge $StartDate -and $_.ActivityDateTime -le $EndDate
}
# Extract useful properties
$Results = $FilteredLogs | Select-Object `
ActivityDateTime,
ActivityDisplayName,
@{Name="User";Expression={$_.InitiatedBy.User.UserPrincipalName}},
@{Name="SearchQuery";Expression={$_.AdditionalDetails | Where-Object {$_.Key -eq "QueryText"} | Select-Object -ExpandProperty Value}},
@{Name="Workload";Expression={$_.LoggedByService}}
# Export to CSV
$Results | Export-Csv "M365_SearchActivity_Report.csv" -NoTypeInformation
Write-Host "✅ Search activity report generated successfully!"
| ActivityDateTime | User | SearchQuery | Workload |
| 2026-04-20 | user@domain.com | HR Policy | SharePoint |
| 2026-04-21 | admin@domain.com | Project Plan | OneDrive |
Example keywords:
👉 Useful for security monitoring and compliance
Users searching for:
👉 Helps identify missing documentation
Search behavior indicates:
👉 Critical for Copilot adoption
powershell.exe -File "SearchReport.ps1"
$SensitiveKeywords = "salary","confidential","resignation"
$Alerts = $Results | Where-Object {
$SensitiveKeywords -contains $_.SearchQuery
}
if ($Alerts) {
Write-Host "⚠️ Sensitive searches detected!"
}
| Error | Cause | Solution |
| Insufficient privileges |
Missing permissions |
Connect-MgGraph -Scopes "AuditLog.Read.All" |
| No results returned |
|
|
| SearchQueryPerformed not found | Tenant does not support Audit Premium | Upgrade to:
|
| QueryText missing | Telemetry limitation | $FilteredLogs | Format-List * Inspect full payload |
| Throttling | Too many requests | Start-Sleep -Seconds 2 |
| Scenario | Benefit |
| Search analytics | Improve discoverability |
| Security monitoring | Detect sensitive searches✅ |
| Admin insights | Understand behavior |
| Copilot readiness | Optimize knowledge base |
Tracking Microsoft 365 search activity provides deep visibility into user behavior, but it comes with an important caveat—it requires Audit Premium (E5-level licensing).
Using Microsoft Graph PowerShell, you can:
👉 This guide gives you a real-world, script-driven approach to get started.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex