By default, deleted objects remain in the Recycle Bin for 180 days (deletedObjectLifetime). You can modify this value based on your organization's needs. Check the current setting:
Get-ADObject "CN=Directory Service,CN=Services,CN=Configuration,$((Get-ADRootDSE).configurationNamingContext)" -Properties deletedObjectLifetime | Format-List deletedObjectLifetime
If the value is <not set>, it defaults to 180 days. To modify it (for example, to 365 days):
Set-ADObject "CN=Directory Service,CN=Services,CN=Configuration,$((Get-ADRootDSE).configurationNamingContext)" -Replace @{deletedObjectLifetime=365}
Also check the tombstone lifetime, which determines when objects are permanently purged:
Get-ADObject "CN=Directory Service,CN=Services,CN=Configuration,$((Get-ADRootDSE).configurationNamingContext)" -Properties tombstoneLifetime | Format-List tombstoneLifetime
The tombstone lifetime should be longer than the deleted object lifetime to ensure proper cleanup.
Pro tip: Set deletedObjectLifetime to match your backup retention policy. This ensures you have multiple recovery options available.