Enabling Versioning in SharePoint Lists using PnP PowerShell

Loading

Versioning in SharePoint lists helps track changes, recover previous versions, and maintain data integrity. Using PnP PowerShell, you can efficiently enable, configure, and manage versioning settings for SharePoint lists.

What You’ll Learn:

✔️ How to connect to SharePoint Online
✔️ How to enable versioning for a SharePoint list
✔️ How to set version limits for list items
✔️ How to disable versioning if needed


Prerequisites

Before enabling versioning, ensure that:
PnP PowerShell is installed
You have the necessary SharePoint permissions
You know the SharePoint site URL


Step 1: Install and Import PnP PowerShell

If you haven’t installed PnP PowerShell, install it using:

Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force

Then, import the module:

powershellCopyEditImport-Module PnP.PowerShell

PnP PowerShell is ready!


Step 2: Connect to SharePoint Online

Before making changes, connect to your SharePoint site:

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive

🔹 Replace "yourtenant" with your tenant name
🔹 Replace "yoursite" with the site name

Connected successfully!


Step 3: Enable Versioning for a SharePoint List

To enable versioning on a list, use the following script:

# Define the list name
$listName = "Project Documents"

# Enable versioning
Set-PnPList -Identity $listName -EnableVersioning $true

🔹 This enables versioning on the "Project Documents" list.

Versioning enabled!


Step 4: Set Version Limits

To limit the number of versions stored, use:

# Define version limits
$majorVersions = 50 # Keep the last 50 major versions

# Set versioning limits
Set-PnPList -Identity $listName -MajorVersions $majorVersions

🔹 This ensures that only 50 major versions are retained.

Version limits set!


Step 5: Enable Minor Versions (Drafts) (Optional)

For lists that require approval workflows, enable minor versions:

# Enable minor versions
Set-PnPList -Identity $listName -EnableMinorVersions $true -MajorVersions 50 -MinorVersions 10

🔹 This keeps 10 minor versions along with 50 major versions.

Minor versions enabled!


Step 6: Disable Versioning (If Needed)

If you want to turn off versioning, use:

# Disable versioning
Set-PnPList -Identity $listName -EnableVersioning $false

🔹 This disables versioning, but previous versions remain stored unless manually deleted.

Versioning disabled!


Step 7: Verify Versioning Settings

To check if versioning is enabled, run:

# Get versioning settings
Get-PnPList -Identity $listName | Select-Object Title, EnableVersioning, MajorVersions, EnableMinorVersions, MinorVersions

Versioning settings verified!


Common Errors & Solutions

ErrorCauseSolution
Access DeniedInsufficient permissionsEnsure you have Full Control on the list
Cannot find listIncorrect list nameUse Get-PnPList to verify the name
Invalid version limitsExceeding SharePoint limitsUse a reasonable version count (e.g., 50 major, 10 minor)

Leave a Reply

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