Commands › Exchange Online
Set-UnifiedAuditLogRetentionPolicy
For more information, see Security & Compliance PowerShell. Use the Set-UnifiedAuditLogRetentionPolicy cmdlet to modify audit log retention policies in the Microsoft Defender portal or the Microsoft Purview compliance portal.
Quick start script
# Set-UnifiedAuditLogRetentionPolicy — quick start (serv365.ai)
# 1. Connect (app-only shown; interactive: omit the certificate parameters)
Connect-ExchangeOnline -CertificateThumbprint $thumb -AppId $appId -Organization $org
# 2. Capture the current state first — you cannot roll back what you never recorded
$before = Get-UnifiedAuditLogRetentionPolicy
$before | Format-List
# 3. Make the change (dry run first)
Set-UnifiedAuditLogRetentionPolicy -Identity <PolicyIdParameter> -Priority <Int32> -RetentionDuration <UnifiedAuditLogRetentionDuration> -WhatIf
Set-UnifiedAuditLogRetentionPolicy -Identity <PolicyIdParameter> -Priority <Int32> -RetentionDuration <UnifiedAuditLogRetentionDuration>
# 4. Verify and diff
$after = Get-UnifiedAuditLogRetentionPolicy
Compare-Object ($before | Out-String) ($after | Out-String)
Syntax
Set-UnifiedAuditLogRetentionPolicy [-Identity] <PolicyIdParameter> -Priority <Int32> -RetentionDuration <UnifiedAuditLogRetentionDuration>
[-Confirm]
[-Description <String>]
[-Operations <MultiValuedProperty>]
[-RecordTypes <MultiValuedProperty>]
[-UserIds <MultiValuedProperty>]
[-WhatIf]
[<CommonParameters>]
Parameters (9)
Reference facts derived from Microsoft documentation, © Microsoft, licensed CC BY 4.0; restructured with original guidance by serv365.ai.