Content approval workflows in SharePoint Online ensure that only reviewed and approved documents/pages are published. Automating this process with PnP PowerShell helps:
Enforce approval policies
Improve governance
Reduce manual intervention
With PnP PowerShell, we can:
✔ Enable content approval
✔ Configure approval workflows
✔ Assign approvers
Step 1: Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSite"
Connect-PnPOnline -Url $siteUrl -Interactive
Write-Host " Connected to SharePoint Online"
✔ Ensures secure authentication.
Step 2: Enable Content Approval for a Library
To enable content approval in a Document Library:
$libraryName = "Documents"
Set-PnPList -Identity $libraryName -EnableModeration $true
Write-Host " Content approval enabled for '$libraryName'"
✔ Requires approval before publishing.
Step 3: Set Up an Approval Workflow
a) Get Workflow Subscription ID
$workflows = Get-PnPWorkflowSubscription -List $libraryName
$approvalWorkflow = $workflows | Where-Object { $_.Name -eq "Approval - SharePoint 2010" }
if ($approvalWorkflow) {
Write-Host " Approval workflow found: $($approvalWorkflow.Name)"
} else {
Write-Host " No approval workflow found. Please add one manually or through Power Automate."
}
✔ Retrieves existing approval workflows.
b) Associate Workflow with Library
if ($approvalWorkflow) {
Add-PnPWorkflowAssociation -List $libraryName -Name "Document Approval Workflow" -WorkflowSubscription $approvalWorkflow
Write-Host " Approval workflow applied to '$libraryName'"
}
✔ Assigns workflow to the library.
Step 4: Assign Approvers Automatically
Set a specific group or user as an approver:
$approverGroup = "Content Approvers"
Set-PnPListItem -List $libraryName -Identity 1 -Values @{"_ModerationStatus"=2; "Approver"=$approverGroup}
Write-Host " Approvers assigned: $approverGroup"
✔ Defines who reviews content.
Step 5: Automate Approval Notifications
Send an email to approvers when new content needs review:
$approvers = Get-PnPGroupMembers -Group $approverGroup
foreach ($approver in $approvers) {
Send-PnPMail -To $approver.Email -Subject "Approval Needed" -Body "A new document needs your approval."
Write-Host " Notification sent to $($approver.Email)"
}
✔ Ensures timely approvals.
Step 6: Automate the Script (Task Scheduler)
Run this script daily to check for unapproved content:
$taskAction = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\ContentApproval.ps1"
$taskTrigger = New-ScheduledTaskTrigger -Daily -At 9AM
Register-ScheduledTask -TaskName "Content Approval Automation" -Action $taskAction -Trigger $taskTrigger -RunLevel Highest
✔ Automates ongoing approvals.