Enabling Content Approval on a SharePoint List using PnP PowerShell

Loading

Content Approval in SharePoint ensures that new or modified items are not visible to all users until they are approved. This is useful for quality control, compliance, and governance in SharePoint lists.

With PnP PowerShell, we can efficiently enable Content Approval on a list, manage approval settings, and automate approval processes.


What You’ll Learn:

✔️ How to connect to SharePoint Online
✔️ How to enable Content Approval on a list
✔️ How to configure approval settings
✔️ How to approve/reject items using PowerShell


Prerequisites

Before proceeding, ensure that:
PnP PowerShell is installed
You have SharePoint Online Admin or Owner permissions
You know the SharePoint site URL and list name


Step 1: Install and Import PnP PowerShell

If not installed, install PnP PowerShell:

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

Then, import the module:

Import-Module PnP.PowerShell

PnP PowerShell is ready!


Step 2: Connect to SharePoint Online

To connect to your SharePoint site, run:

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

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

Connected successfully!


Step 3: Enable Content Approval on a SharePoint List

To enable Content Approval on a specific list:

# Define variables
$listName = "Documents" # Change to your list name

# Enable Content Approval
Set-PnPList -Identity $listName -EnableModeration $true

Write-Host "Content Approval enabled on list '$listName'."

Content Approval is now active!


Step 4: Configure Content Approval Settings

To restrict item visibility until approval:

# Configure Draft Item Security
Set-PnPList -Identity $listName -DraftVersionVisibility 2

Write-Host "Only users who can approve items will see draft items."

🔹 Draft Visibility Levels:

  • 0All users can see drafts
  • 1Users with Edit Permissions can see drafts
  • 2Only Approvers can see drafts

Content Approval settings configured!


Step 5: Approving or Rejecting Items in the List

To approve an item, use:

# Define variables
$itemId = 5 # Change to the item ID
$comment = "Approved by admin"

# Approve item
Set-PnPListItem -List $listName -Identity $itemId -Approve $comment

Write-Host "Item ID $itemId approved."

Item approved successfully!

To reject an item, use:

# Define variables
$itemId = 5 # Change to the item ID
$comment = "Rejected due to missing details"

# Reject item
Set-PnPListItem -List $listName -Identity $itemId -Reject $comment

Write-Host "Item ID $itemId rejected."

Item rejected successfully!


Step 6: Bulk Approving or Rejecting Items

To approve all pending items, use:

# Get all pending items
$items = Get-PnPListItem -List $listName | Where-Object { $_["Approval Status"] -eq "Pending" }

foreach ($item in $items) {
$itemId = $item.Id
Set-PnPListItem -List $listName -Identity $itemId -Approve "Bulk approval"
Write-Host "Approved item ID $itemId"
}

Write-Host "All pending items approved!"

To reject all pending items, use:

# Get all pending items
$items = Get-PnPListItem -List $listName | Where-Object { $_["Approval Status"] -eq "Pending" }

foreach ($item in $items) {
$itemId = $item.Id
Set-PnPListItem -List $listName -Identity $itemId -Reject "Bulk rejection"
Write-Host "Rejected item ID $itemId"
}

Write-Host "All pending items rejected!"

Bulk approval/rejection completed!


Step 7: Disable Content Approval (If Needed)

To disable Content Approval, run:

# Disable Content Approval
Set-PnPList -Identity $listName -EnableModeration $false

Write-Host "Content Approval disabled on list '$listName'."

Content Approval turned off!


Common Errors & Solutions

ErrorCauseSolution
Access DeniedInsufficient permissionsEnsure you have Owner/Admin rights
Cannot find listIncorrect list nameVerify the list name using Get-PnPList
Item ID not foundInvalid item IDUse Get-PnPListItem to check item existence

Leave a Reply

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