Skip to content

/config/sharepoint-online/orphanedpersonalsitesretentionperiod

OneDrive retention for deleted users: Set-SPOTenant -OrphanedPersonalSitesRetentionPeriod

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
SharePoint Online PowerShell
file
SharePoint Online tenant settings (Set-SPOTenant)
key
OrphanedPersonalSitesRetentionPeriod
type
Int32 (days, 30-3650)
default
30

OrphanedPersonalSitesRetentionPeriod is the number of days a OneDrive is kept after its owner's account is deleted from Microsoft Entra ID. The default is 30 days; valid values are 30 to 3650. Set it after Connect-SPOService -Url https://contoso-admin.sharepoint.com:

powershell
Set-SPOTenant -OrphanedPersonalSitesRetentionPeriod 365
Get-SPOTenant | Select-Object OrphanedPersonalSitesRetentionPeriod

The same value can be changed in the SharePoint admin center (OneDrive retention setting).

The parameter is an Int32 in module 16.0.27709.12000 (checked offline; the range is enforced by the service, not by a PowerShell validation attribute):

powershell
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
$par = (Get-Command Set-SPOTenant).Parameters['OrphanedPersonalSitesRetentionPeriod']
$t = $par.ParameterType
if ($t.IsGenericType) { $t = $t.GetGenericArguments()[0] }
'Type: ' + $t.Name
'Validation attributes: ' + @($par.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateArgumentsAttribute] }).Count

Output

Type: Int32
Validation attributes: 0

What happens when a user is deleted

  1. The user is deleted in the Microsoft 365 admin center or removed by directory synchronization. Blocking sign-in or removing the license does not start this process.
  2. The OneDrive is marked for deletion. If the user has a manager in Entra ID, the manager gets access and an email; otherwise the secondary owner set in the SharePoint admin center does (when access delegation is enabled).
  3. Seven days before the period ends, a reminder email is sent.
  4. At the end of the period the OneDrive goes to the site collection recycle bin for 93 days, where it can be restored only with PowerShell.

Retention policies win

Microsoft Purview retention policies and labels that cover OneDrive take precedence: content can be kept longer than this period, or deleted earlier. A OneDrive on eDiscovery hold is not deleted until the hold is removed. Use a retention policy with -OneDriveLocation when content must be kept for a fixed time.

Sources