office-365-advent-calendar
Scenario

By default, libraries in SharePoint Online keep the last 500 major versions of a item, but lists have no versioning turned on. And while you can easily finetune the settings for all lists and libraries in a site, it may be good to know how versioning is set on each library before you look at changing those settings. Today’s post provides you with a script that retrieves all versioning related information (everything you seen on the ‘Versioning settings’ page of a list/library) from all lists and libraries within a given site.

Code

$cred = Get-Credential
Connect-PnPOnline -url https://mytenant.sharepoint.com/sites/testsite -credentials $cred

$lists = Get-PnPList

$VersioningDetails = @()
foreach($list in $lists) {
	$VersioningDetails += New-Object PSObject -Property @{
		'List' = $list.Title
		'Require Content Approval' = $list.EnableModeration
		'Versioning Enabled' = $list.EnableVersioning
		'Major Version limit' = $list.MajorVersionLimit
		'Draft Version limit' = $list.MajorWithMinorVersionsLimit
		'Drafts visible to' = $list.DraftVersionVisibility
		'Checkout required' = $list.ForceCheckout
	}
}

$VersioningDetails | Select 'List', 'Require Content Approval', 'Versioning Enabled',`
'Major Version limit', 'Draft Version limit', 'Drafts visible to', 'Checkout required'`
| Export-Csv versioningdetails.csv

Code on GitHub

Note: By default, all system libraries such as Solutions Gallery, Master Page Gallery, Web Part Gallery, User Information List, etc. are included.

Here’s a sample output, excluding the system libraries:

6 thoughts on “Office 365 Advent Calendar – 08 Get Versioning Details for all Lists in a SharePoint Online Site”

Leave a Reply to Rene Modery (@modery) Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.