Table of Contents Overview ApplicationSupported lists and librariesRequired permissionsWhen versions are createdTurn on versioning from the User InterfaceEnable versioning for a list using PowerShell PrerequisitesStep-by-step commentsFull codeMinor versioning When versions are createdMinor versioning from User InterfacePowershellFull CodeDownload The scripts are available also for download from the Technet Script Gallery:Other languagesRelated articles
Versioning in lists and libraries enables us to track and manage information as it evolves and to view and restore earlier versions if necessary. That is very useful, e.g. when people realize that earlier versions of an item might be more accurate than later ones. Some organizations retain multiple versions of items in their lists for legal reasons or audit purposes.1
Versioning has multiple uses. With the setting enabled, we can:
* Track history of a version When versioning is enabled, we can see when an item or file was changed and who changed it. We can also see when properties (information about the file) were changed. For example, if someone changes the due date of a list item, that information appears in the version history. We can also see the comments people make when they check files into libraries.
* Restore a previous version If we made a mistake in a current version, if the current version is corrupt, or if we simply like a previous version better, we can replace the current version with a previous one. The restored version becomes the new current version.
* View a previous version We can view a previous version without overwriting our current version. If we are viewing version history within a Microsoft Office document, such as a Word or Excel file, we can compare the two versions to determine what the differences are. From: How does versioning work in a list or library?
Versioning is available for list items in all default list types—including calendars, issue tracking lists, and custom lists. It is also available for all file types that can be stored in libraries, including Web Part pages. By default, versioning is turned off (apart from new OneDrive for Business libraries)
Anyone with permissions to manage lists can turn version on or off for a library.2 When we look at the default permission levels in the tenant we can see that Full Control, Design or Edit include the permissions to manage lists.3 We can view it either in the table here or on our own tenant under : https://TENANT.sharepoint.com/sites/SITECOLLECTIONNAME/_layouts/15/start.aspx#/_layouts/15/editrole.aspx?role=ROLENAME , for example:
https://trialtrial125.sharepoint.com/sites/TeamsiteWithLibraries/_layouts/15/start.aspx#/_layouts/15/editrole.aspx?role=Design
We can also create a custom permission level that will include "Manage Lists" permissions for users to be able to change the versioning settings.
There are several actions that trigger version creation. When versioning is enabled, versions are created in the following situations:
* When a list item or file is first created or when a file is uploaded. Note that if you have enabled a library setting that requires file checkout, you have to check the file in to create its first version.
* When a file is uploaded that has the same name as an existing file and the Add as a new version to existing files check box is selected.
* When the properties of a list item or file are changed.
* When a file is opened, edited, and saved. A version is created when we first click Save. It retains the new version number for the duration of the current editing session, even though we might save it several times. When we close it and then reopen it for another editing session, another version is created.
* During co-authoring of a document, when a different user begins working on the document or when a user clicks save to upload changes to the library. The default time period for creating new versions during co-authoring is 30 minutes. This is configurable per web application in SharePoint on-premises. This setting is not configurable in SharePoint Online.
In the ISE Window, add the paths to SharePoint Online SDK installed earlier. Verify if the paths are exactly the same, e.g. on Windows Server, we may need to change 15 into 16:
Add-Type -Path
"c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
"c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Enter the credentials, the site, and list where we want to change the versioning setting
$AdminPassword
=Read-Host -Prompt
"Enter password"
-AsSecureString
$username
=
"trial@trialtrial125.onmicrosoft.com"
$Url
"https://trialtrial125.sharepoint.com/sites/teamsitewithlibraries"
$ListTitle
"Not-Empty-Document-Library"
$Versioning
$true
function
Set-SPOListVersioning
{
}
param (
[Parameter(Mandatory=
,Position=0)]
[string]
$ListName
,
,Position=1)]
[bool]
,Position=2)]
$Username
,Position=3)]
,Position=4)]
$password
)
$ctx
=New-Object Microsoft.SharePoint.Client.ClientContext(
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials(
.ExecuteQuery()
$ll
.Web.Lists.GetByTitle(
.Load(
.EnableVersioning =
.Update()
try
Write-Host
"Done"
-ForegroundColor Green
catch [Net.WebException]
"Failed"
$_
.Exception.ToString() -ForegroundColor Red
Set-SPOListVersioning -ListName
-Versioning
-Username
-Url
-password
Export-ModuleMember
"Set-SPOListVersioning"
#
# Created by Arleta Wanat, 2015
.Web)
# Paths to SDK. Please verify location on your computer.
# Insert the credentials
and
the name of the site
list
You can also download it here.
The multiple possibilities mean that there can be up to three current versions of a file at any given time: the checked-out version, the latest minor or draft version, and the latest published or major version. All other versions are considered historical versions. Some current versions are only visible to users who have permissions to view them.5
Numbering
.EnableMinorVersions =
Enable versioning programmatically using Powershell and CSOM Enable minor versions programmatically using Powershell and CSOM