Change version limits on OneDrive using PowerShell (Preview)
By default, organization version history settings are applied to all new OneDrive accounts. As a global or SharePoint admin in Microsoft 365, you can set the version limits on OneDrive storage for a specific user.
Follow these steps to manage Version history limits for a site by using PowerShell.
Download the latest SharePoint Online Management Shell.
Note
If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall SharePoint Online Management Shell.
Connect to SharePoint as a Global Administrator or SharePoint Administrator in Microsoft 365. To learn how, see Getting started with SharePoint Online Management Shell.
Run one of the following commands to manage Version history limits for a specific user:
Action | PowerShell Command |
---|---|
View the version history limits set for a user | Get-SPOSite -Identity $siteUrl | fl Url, EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersionLimit |
Set automatic Version history limits for a user | Set-SPOSite -Identity $siteUrl -EnableAutoExpirationVersionTrim $true |
Set manual limits with count and time parameters for a user | Set-SPOSite -Identity $siteUrl -EnableAutoExpirationVersionTrim $false -MajorVersionLimit <delete major versions exceeding limit> -MajorWithMinorVersionsLimit <delete minor versions exceeding limit> -ExpireVersionsAfterDays <delete versions exceeding time limit set in days> |
Set manual limits with count with no expiration limit for a user | To set manual limits with count limits set the -ExpireVersionsAfterDays parameter to 0:Set-SPOSite -Identity $siteUrl -EnableAutoExpirationVersionTrim $false -MajorVersionLimit <delete major versions exceeding limit> -MajorWithMinorVersionsLimit <delete minor versions exceeding limit> -ExpireVersionsAfterDays 0 |
Clear the existing Version history limits for a user Note: Clearing a setting for a user applies to new versions created on files stored on the user’s OneDrive account and doesn't trim existing versions. |
Remove-SPOSiteVersionPolicyJob -Identity $siteUrl |
Learn More
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for