SharePoint Online: Audit Versioning Settings on All Lists and Libraries using PowerShell

Requirement: Audit versioning settings for all lists and libraries in the SharePoint Online site collection.

powershell to get versioning settings in sharepoint online

PowerShell to Generate Versioning Settings Analysis for SharePoint Online Site Collection:

Looking for a way to audit versioning on all lists and libraries in your SharePoint Online environment? PowerShell can help! In this post, we’ll look at the PowerShell script that allows you to analyze the versioning settings for all your lists and libraries in your SharePoint Online site.

Let’s audit versioning settings on all lists and libraries of the given site collection.

#Import SharePoint Online module
Import-Module Microsoft.Online.SharePoint.Powershell

Function Audit-VersioningSettings()
{
  param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ReportOutput
    )
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get all subsites and Lists from the site
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)  
        $Lists = $Web.Lists
        $Ctx.Load($Lists)        
        $Ctx.ExecuteQuery()
        
        $VersioningData = @()
        Write-host -f Yellow "Processing Site: "$SiteURL
        #Iterate through each list in a site and get versioning configuration
        ForEach($List in $Lists)
        {
            $VersioningData += New-Object PSObject -Property @{
            'Site' = $SiteURL
            'List' = $List.Title
            'Versioning Enabled' = $List.EnableVersioning
            'Major Versions Limit' = $List.MajorVersionLimit
            'Draft Versions Limit' = $List.MajorWithMinorVersionsLimit
            'Draft Item Security' = $List.DraftVersionVisibility
            'Content Approval Required' = $List.EnableModeration
            'Checkout Required' = $List.ForceCheckout
            }
        }
        #Export the data to CSV
        $VersioningData | Export-Csv $ReportOutput -Append -NoTypeInformation

        #Iterate through each subsite in the current web
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function recursively to process all subsites underneaththe current web
            Audit-VersioningSettings -SiteURL $Subweb.URL -ReportOutput $ReportOutput
        }
     }
    Catch {
        write-host -f Red "Error Auditing versioning Settings!" $_.Exception.Message
    } 
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ReportOutput="C:\Temp\VersioningData.csv"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Delete the Output report file if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }

#Call the function to generate versioning data audit report
Audit-VersioningSettings -SiteURL $SiteURL -ReportOutput $ReportOutput

This PowerShell script generates a CSV output provided in the $ReportOutput parameter.

sharepoint online versioning analysis report using powershell

Please note, this script gets versioning configurations for a given site collection. You can retrieve all site collections, loop through and call the function to get version history analysis for all site collections in SharePoint Online.

How to Exclude System Lists and Libraries?

Well, the above script scans all lists and libraries, including system lists. Here is the change to exclude all system lists (You can add any missing!)

#Exclude system lists
$ExcludedLists = @("Access Requests","App Packages","appdata","appfiles","Apps in Testing","Cache Profiles","Composed Looks","Content and Structure Reports","Content type publishing error log","Converted Forms", "Device Channels","Form Templates","fpdatasources","Get started with Apps for Office and SharePoint","List Template Gallery", "Long Running Operation Status","Maintenance Log Library"            ,"Master Docs","Master Page Gallery","MicroFeed","NintexFormXml","Quick Deploy Items","Relationships List","Reusable Content","Reporting Metadata", "Reporting Templates", "Search Config List","Site Assets","Site Pages", "Solution Gallery","Style Library","Suggested Content Browser Locations","Theme Gallery", "TaxonomyHiddenList","User Information List","Web Part Gallery","wfpub","wfsvc","Workflow History","Workflow Tasks")

$VersioningData = @()
Write-host -f Yellow "Processing Site: "$SiteURL
#Iterate through each list in a site and get versioning configuration
ForEach($List in $Lists)
{
    if($ExcludedLists -NotContains $List.Title -and $List.Hidden -eq $False)
    {
        $VersioningData += New-Object PSObject -Property @{
        'Site' = $SiteURL
        'List' = $List.Title
        'Versioning Enabled' = $List.EnableVersioning
        'Major Versions Limit' = $List.MajorVersionLimit
        'Draft Versions Limit' = $List.MajorWithMinorVersionsLimit
        'Draft Item Security' = $List.DraftVersionVisibility
        'Content Approval Required' = $List.EnableModeration
        'Checkout Required' = $List.ForceCheckout
        }
    }
}

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

7 thoughts on “SharePoint Online: Audit Versioning Settings on All Lists and Libraries using PowerShell

  • Can I use this script somehow to view a list of the top version sizes of all of my non-system Lists? If so, how?

    Thanks!

    Reply
    • The code can be amended, However the easier way would be: Format the generated CSV output as Table, Sort and Filter!

      Reply
  • Not working if I try to run https://crescent.sharepoint.com/Sites/ As all my SPO sites are under this.

    Reply
    • Basically I’m trying to generate report for all the sites under our tenant.

      Reply
      • Well, You have to wrap everything inside a function, Loop through the sites in your tenant and call the function to audit version settings.

        Reply
  • This report contains all system lists and libraries, such as Master Page Gallery, MicroFeed, Site Assets, Site Pages, Composed Looks, etc. How do I exclude them?

    Reply

Leave a Reply

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