Skip to main content

Posts

How to List All SharePoint Lists with PowerShell Using PnP

When managing SharePoint Online, administrators often need to retrieve a list of all libraries and lists in a site. With the PowerShell PnP module, this process is quick and efficient. In this post, we’ll walk through a simple script that connects to a SharePoint site and retrieves the title and description of all lists. Prerequisites To follow along, make sure you have the PnP PowerShell module installed. You can install it using: Install-Module -Name PnP.PowerShell Script Overview Here's the script that connects to your SharePoint Online site and displays the title and description of each list: # Connect to SharePoint site Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive # Get all lists $lists = Get-PnPList # Select and display Title and Description $lists | Select-Object Title, Description | Format-Table -AutoSize Use Cases Auditing site contents Documenting SharePoint structure Identifying unused or unnamed lists

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)...

Convert IST to CST/CDT in PowerShell – Handling Daylight Saving Time (DST)

Working across time zones can be tricky, especially when Daylight Saving Time (DST) is involved. If you’re dealing with automation, scheduling, or data transformation tasks, converting between Indian Standard Time (IST) and Central Time (CST/CDT) becomes essential. In this post, I’ll walk you through a PowerShell function that smartly handles the conversion of an IST datetime to either CST (Central Standard Time) or CDT (Central Daylight Time), depending on the date and DST rules. The PowerShell Function Below is a reusable PowerShell function that converts IST to CST/CDT accurately by accounting for Daylight Saving Time. function Convert-ISTToCSTorDST {     param (         [datetime]$ISTDate    # Input IST DateTime to be converted     )     # Central Time Zone Information     $centralTimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("Central Standard Time")          # Check if the g...

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...

How to Split a Large Excel File into Smaller Chunks Using PowerShell

Working with massive Excel files can be cumbersome—slow to open, hard to process, and error-prone in automation. If you’re dealing with a large dataset and need to split it into smaller, manageable files, PowerShell offers a powerful and efficient way to do it—especially with the help of the ImportExcel module. In this guide, I’ll walk you through a simple script that takes a large Excel file and splits it into multiple smaller Excel files, each containing a defined number of records. Requirements PowerShell ImportExcel module You can install it via PowerShell with:              Install-Module -Name ImportExcel # Import the ImportExcel module Import-Module ImportExcel # Path to the large Excel file $excelFilePath = "[LocalFilePathwithFileExtention]" # Define the chunk size (e.g., 10,000 records per chunk) $chunkSize = 10000 # Read the Excel file $excelData = Import-Excel -Path $excelFilePath # Calculate how many chunks are needed $totalRo...

Import Sharepoint List data with PnP Powershell from excel

  $siteUrl = "[SiteURL]" $listName = "[List NAME]" $excelFilePath = "C:\Users\user254\Downloads\ObservationsImport1.xlsx"  $lookupColumns = @{     "Location_ID" = "WS_Locations"     "Line_ID" = "WS_Line"     "Area_ID" = "WS_Area"     "Sub_Area_ID" = "WS_Sub_Area"     "Category_ID" = "WS_Category"     "Sub_Category_ID" = "WS_Sub_Category" } $nonLookupColumns = @("OBSERVATION_DATE", "SHIFT", "TYPE", "BEHAVIOR", "AT_RISK_BY_UNSAFE_COND", "COMMENTS", "TIME_ZONE", "ROLE") Connect-PnPOnline -Url $siteUrl -UseWebLogin $excelData = Import-Excel -Path $excelFilePath $excelData.Count $lookupDataCache = @{} function Get-LookupId {     param (         [string]$lookupColumn,         [string]$lookupValue     )     $itemId=0                    $lookupListName = $lookupColumn...

How to Duplicate a SharePoint List Using PnP PowerShell

When working with SharePoint, you might find yourself in situations where you need to create a duplicate of an existing list. This could be for backup purposes, testing, or simply as a template for new content. Fortunately, using PnP PowerShell , you can automate this process in just a few easy steps. In this blog post, I'll walk you through how to create a duplicate of a SharePoint list, including its structure and items, using a simple PowerShell script with PnP PowerShell commands. What is PnP PowerShell? PnP PowerShell is a powerful library of cmdlets that helps you interact with SharePoint and Office 365. It allows you to manage SharePoint Online or SharePoint Server environments from the command line, automating common tasks and simplifying your SharePoint administration. Prerequisites: Before we dive into the script, make sure you have the following: PnP PowerShell module installed . If you haven't installed it yet, you can do so by running this command: Install-Module -...