Forum Discussion
Sharepoint versions
Hi LeonPavesic
thanks for your quick reply!
Unfortunately I get the following message when trying to change:
"You must enter a number between 100 and 50,000."
Hi CSHero,
I have made some research, the message you are receiving indicates that the minimum number of major versions that you can keep in SharePoint Online is 100. This is a security measure to prevent accidental data loss.
There are a few workarounds that you can use to limit versioning to 20 versions or less:
- Use minor versions. Minor versions are not included in the major version count. So, if you set the major version limit to 100 and the minor version limit to 20, you will be able to keep a total of 120 versions of your files.
- Use a third-party versioning tool. There are a number of third-party tools available that can help you to manage versioning in SharePoint Online. These tools typically offer more flexibility than the built-in versioning features in SharePoint Online, such as the ability to set custom versioning limits and to create versioning policies.
- Use PowerShell to delete old versions. You can use the PowerShell script that LeonPavesic provided to delete all versions of files and list items except the last 20. However, it is important to note that this script will delete all versions of files and list items, even if they are still needed. Therefore, it is important to make sure that you have a backup of your data before running this script.
Which workaround you choose will depend on your specific needs and requirements.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
- CSHeroOct 04, 2023Copper Contributor
Hi LeonPavesic,
unfortunately, the following error occurs with your script:
"No parameter was found that corresponds to the parameter name "Url"."Do you have another suggestion?
Thank you.
- LeonPavesicOct 04, 2023Silver Contributor
Hi CSHero,
thanks dor your update.
To fix the error message "No parameter was found that corresponds to the parameter name 'Url'", you need to add the -Url parameter to the Get-PnPWeb cmdlet. The -Url parameter specifies the URL of the SharePoint site or library that you want to manage.is to use the following script:
# Connect to SharePoint Online using interactive login Connect-PnPOnline -UseWebLogin # Get the list of all document libraries in the current site $libraries = Get-PnPWeb -ListInfo # Iterate through each library and delete all versions except the last 20 foreach ($library in $libraries) { # Get the list of all files in the library $files = Get-PnPListItem -List $library.Title # Iterate through each file and delete all versions except the last 20 foreach ($file in $files) { # Get the list of all versions of the file $versions = Get-PnPListItemVersion -List $library.Title -ItemId $file.Id # Delete all versions except the last 20 for ($i = 0; $i -lt $versions.Count - 20; $i++) { Remove-PnPListItemVersion -List $library.Title -ItemId $file.Id -VersionNumber $versions[$i].VersionNumber } } }To use this script, you will need to have the PnP PowerShell module installed. You can install it from the PowerShell Gallery:
Install-Module -Name PnP.PowerShellJust one more time for a reminder: the minimum number of major versions that you can keep in SharePoint Online is 100. This is a security measure to prevent accidental data loss. However, you can use the workaround of using minor versions to limit versioning to 20 versions or less.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)- CSHeroOct 05, 2023Copper Contributor
Hi LeonPavesic
unfortunately your script does not work yet. I get the following errors:"No parameter was found that corresponds to the parameter name "ListInfo" and
"The name "Get-PnPListItemVersion" was not recognized as the name of a cmdlet, function, script file or executable program. Verify the spelling of the name, or that the path is correct (if it is
included), and repeat the operation."I have installed PnP.PowerShell
Thank you!
Kindest regards,
CSHero