Commands › SharePoint Online

Export-SPOQueryLogs

SharePoint Online Microsoft.Online.SharePoint.PowerShell Export-*

Export query logs for a user in an Office 365 tenant. > [!NOTE] > Beginning February 2022, we'll be removing the Export-SPOQueryLogs command from SharePoint in Microsoft 365. We encourage users to instead download their Microsoft Search query history logs from the My Account privacy portal.

Quick start script

# Export-SPOQueryLogs — quick start (serv365.ai)
# 1. Connect (app-only shown; interactive: omit the certificate parameters)
Connect-SPOService -Url https://$org-admin.sharepoint.com

# 2. Run and inspect
Export-SPOQueryLogs -LoginName <String> | Format-List

# 3. Export for evidence / drift tracking
Export-SPOQueryLogs | Export-Clixml .\SPOQueryLogs-$(Get-Date -Format yyyyMMdd).xml

Syntax

Export-SPOQueryLogs [-StartTime <DateTime>] -LoginName <String> -OutputFolder <String> [<CommonParameters>]

Parameters (3)

ParameterTypeRequiredWhat it controls
-LoginName String yes Specifies the login name of the user to export.
-OutputFolder String Target folder where the CSV file is generated.
-StartTime DateTime Specifies from which point of time to export the logs from. Use the date format YYYY-MM-DD.

Reference facts derived from Microsoft documentation, © Microsoft, licensed CC BY 4.0; restructured with original guidance by serv365.ai.