How to Replace Search-UnifiedAuditLog with Microsoft Graph

Search-UnifiedAuditLog retirement

The Search-UnifiedAuditLog PowerShell cmdlet retires on October 15, 2027. Many of us use it to retrieve audit logs, generate reports, and investigate user activities, so any script built on it will need attention.

Audit log search in the Microsoft Purview portal works as usual. Only the PowerShell cmdlet is going away.

The Microsoft Graph AuditLogQuery API is the way forward for programmatic audit searches, ๐Œ๐ข๐œ๐ซ๐จ๐ฌ๐จ๐Ÿ๐ญ ๐†๐ซ๐š๐ฉ๐ก ๐€๐ฎ๐๐ข๐ญ๐‹๐จ๐ ๐๐ฎ๐ž๐ซ๐ฒ ๐€๐๐ˆ ๐ข๐ฌ ๐ญ๐ก๐ž ๐ฐ๐š๐ฒ ๐Ÿ๐จ๐ซ๐ฐ๐š๐ซ๐ ๐Ÿ๐จ๐ซ ๐ฉ๐ซ๐จ๐ ๐ซ๐š๐ฆ๐ฆ๐š๐ญ๐ข๐œ ๐š๐ฎ๐๐ข๐ญ ๐ฌ๐ž๐š๐ซ๐œ๐ก๐ž๐ฌ, and it brings clear improvements:

The new API supports up to 1 million audit records per query, up from 50,000 records per search with the existing cmdlet, improving scalability and reliability. More importantly, it supports workload-level permissions, such as AuditLogsQuery-SharePoint.Read.All, allowing administrators to follow the principle of least privilege by granting access only to the audit data required.

Hereโ€™s a checklist to help you transition your existing scripts:

  1. Identify all scripts and tools that use Search-UnifiedAuditLog.
  2. Map the existing cmdlet parameters to the filters supported by the AuditLogQuery API.
  3. Connect to Microsoft Graph with the required AuditLogsQuery permissions.
  4. Submit audit queries using New-MgSecurityAuditLogQuery.
  5. Poll the query status until it shows succeeded.
  6. Check isRecordCountLimitExceeded. If the limit is exceeded, split the date range into smaller queries.
  7. Retrieve the results using Get-MgSecurityAuditLogQueryRecord -All.
  8. Export the retrieved records to your required format or destination.
  9. Configure app-only authentication for scheduled jobs and unattended automation.
  10. Compare the new results with your existing output, validate the reporting logic, and switch over once everything works as expected.

The AuditLogQuery API is already generally available. Start testing your migration early rather than waiting until the retirement deadline. The transition involves changes to query submission, status tracking, and result retrieval, not just replacing one cmdlet with another.

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Powered by Amail.