Skip to main content

PowerShell Script to Bulk Update "Next Review Date" for PDFs in SharePoint Online

  In document management scenarios, it's common to have review schedules for files such as policies, SOPs, or manuals. This blog post walks you through a PowerShell script that automates the process of updating the “Next Review Date” field for all PDF documents in a SharePoint Online document library.

We’ll use the PnP PowerShell module to fetch and update items efficiently, while also handling time zone specifics like CST/CDT.

Prerequisites

Before running the script, ensure:

  • You have the PnP PowerShell module installed:
    Install-Module PnP.PowerShell -Scope CurrentUser

  • You have the correct Site Collection URL and Library Internal Field Name.

  • Your account has permission to modify list items in the target document library.

What the Script Does
1. Connects to SharePoint Online using PnP PowerShell.

2. Filters all PDF documents in the specified library.

3. Calculates a future "Next Review Date" (e.g., 9999-09-09) adjusted for CST or CDT.

4. Updates the metadata field (Next Review Date) for each filtered document.

PowerShell Script

$SiteUrl = "[SiteCollection]"
Connect-PnPOnline -Url $SiteUrl -UseWebLogin 

# Define the Document Library and the field name for Next Review Date
$libraryName = "[LibraryName]"  # Adjust the library name accordingly
$reviewDateField = "Next_x0020_Review_x0020_Date"  # Internal name of the field

# Get all items from the document library, including FileLeafRef
$documents = Get-PnPListItem -List $libraryName -Fields "FileLeafRef"

# Filter for PDF files only
$filteredDocuments = $documents | Where-Object { $_["FileLeafRef"] -like "*.pdf" }

# Set the new review date to a far future date
$newReviewDate = [datetime]"9999-09-09"

# Determine if the date falls under CDT or CST
$centralTimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time")
$isDST = $centralTimeZone.IsDaylightSavingTime($newReviewDate)

# Adjust for time difference from UTC to IST
if ($isDST) {
    $newReviewDate = $newReviewDate.AddHours(10).AddMinutes(30)
} else {
    $newReviewDate = $newReviewDate.AddHours(11).AddMinutes(30)
}

# Loop through filtered documents and update the field
foreach ($document in $filteredDocuments) {
    $fileLeafRef = $document["FileLeafRef"]
    Write-Host "$libraryName Document FileLeafRef: $fileLeafRef"

    Set-PnPListItem -List $libraryName -Identity $document.Id -Values @{ $reviewDateField = $newReviewDate }
}

Notes
  • Next_x0020_Review_x0020_Date is the internal name for the “Next Review Date” field. You can find this in list settings or by inspecting the field using PowerShell or the browser.
  • The script uses a placeholder date 9999-09-09 which might be used for archiving or indefinite review.
  • Adjusting time based on DST (Daylight Saving Time) ensures that timestamps align correctly across regions.
Use Cases
  • Automating document review schedules.
  • Archiving outdated or permanent documents.
  • Preparing metadata for records management.

Comments

Popular posts from this blog

Get App Expiry Dates using Powershell

Step 1: Connect-MsolService Step 2: $applist = Get-MsolServicePrincipal -all  |Where-Object -FilterScript { ($_.DisplayName -notlike "*Microsoft*") -and ($_.DisplayName -notlike "autohost*") -and  ($_.ServicePrincipalNames -notlike "*localhost*") } Step 3: foreach ($appentry in $applist) {     $principalId = $appentry.AppPrincipalId     $principalName = $appentry.DisplayName     Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | ? { $_.Type -eq "Password" } | % { "$principalName;$principalId;" + $_.KeyId.ToString() +";" + $_.StartDate.ToString() + ";" + $_.EndDate.ToString() } | out-file -FilePath d:\appsec.txt -append }

Bulk Import Excel Data to SharePoint List Using PowerShell and PnP

  Managing large datasets in SharePoint can be tricky, especially when you're dealing with Excel files and need to avoid list view threshold issues. In this guide, I’ll walk you through a PowerShell script that efficiently imports data from Excel into a SharePoint Online list using PnP PowerShell — with batching support for performance. Prerequisites Make sure you have the following before running the script: SharePoint Online site URL Excel file with data properly formatted PnP PowerShell module installed ( Install-Module PnP.PowerShell ) Appropriate SharePoint permissions What the Script Does Connects to your SharePoint site Loads and reads an Excel file Converts Excel date values Batches records in groups (to avoid the 5000 item threshold) Adds the items to your SharePoint list or library Logs execution time PowerShell Script $siteUrl = "[Site Collection URL]" Connect-PnPOnline -Url $siteUrl -UseWebLogin # Capture the start time $startTime...

๐Ÿš€ Essential SPFx (SharePoint Framework) Commands for Every Developer

Whether you're new to SharePoint Framework (SPFx) or a seasoned pro, having a go-to list of core commands can significantly improve your development workflow. In this post, we'll walk through the most important SPFx CLI commands—from setting up your environment to packaging and deploying your solution. ๐Ÿ› ️ Setting Up Your SPFx Project Start by scaffolding a new project using the Yeoman generator provided by Microsoft. Make sure Node.js and npm are installed before you proceed. yo @microsoft/sharepoint After scaffolding the project, install all dependencies: npm install To update dependencies later: npm update ๐Ÿ” Trusting the Development Certificate If you're using the local workbench, you need to trust the developer certificate for HTTPS support: gulp trust-dev-cert ๐Ÿงช Running the Local Workbench To build and serve your project locally, use: gulp serve This command starts a local server at: https://localhost:4321/temp/workbench.html You can also test your solution in ShareP...