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
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:
Office 365 Advent Calendar – 08 Get Versioning Details for all Lists in a SharePoint Online Site https://t.co/exNNpo7Twq #office365
RT @nyn3x: #Office365 Advent Calendar – 08 Get Versioning Details for all Lists in a #SharePoint Online Site https://t.co/ZrTRujFEri
Office 365 Advent Calendar – 08 Get Versioning Details for all Lists in a SharePoint Online Site https://t.co/exNNpopuV0 #office365
Office 365 Advent Calendar – 08 Get Versioning Details for all Lists in a SharePoint Online Site https://t.co/vfIr6qJOzH #Office365
Instead of one site, how do I call it for all sites in the tenant?
You’d need to do the following:
1) connect to the tenant, retrieve all sites
2) for each site, loop through all subsites and execute the steps above