SharePoint Document Issues

How to Delete Old SharePoint List Items Using PowerShell Script

Natalie TaylorNatalie Taylor Nov 3, 2026 869 views

Question details

The user wants to automate the deletion of SharePoint list items that are older than a specific date using a PowerShell script, rather than manually deleting every item.

How to Delete Old SharePoint List Items Using PowerShell Script
Product
Microsoft SharePoint
Device & OS
not provided
Scenario
Automating list cleanup to maintain SharePoint performance and storage by selectively removing items based on their creation dates.
Observed behavior
The user needs a script to securely connect to a SharePoint site, calculate a cutoff date, and execute the removal only on items created before that date.
Before you start

Ensure you have the necessary site administrator permissions and that PnP PowerShell is installed on your system. It is highly recommended to run your script in a test environment before executing it on production lists.

Solution 1Recommended

Use PnP PowerShell to Filter and Delete Old Items

Connect to your SharePoint site via PnP PowerShell, set a cutoff date, and loop through list items to delete those created before the specified time.

This method uses the PnP PowerShell module, which provides robust commands for SharePoint Online administration. You will calculate a cutoff date using the Get-Date function and iterate through your list items to remove the matched entries securely.

1
Install PnP PowerShell

Open your PowerShell terminal as an administrator and run 'Install-Module -Name PnP.PowerShell' if the module is not already installed on your system.

2
Connect to the SharePoint Site

Run the connection command to authenticate with your site: 'Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive'.

3
Define Variables and Retrieve Items

Set your target list name and retrieve the items along with their creation dates. For example: '$listName = "Your List Name"' and '$items = Get-PnPListItem -List $listName -Fields "Title","Created"'.

4
Set Cutoff Date and Execute Deletion

Define your threshold, such as 365 days ago: '$cutoffDate = (Get-Date).AddDays(-365)'. Iterate through the items with a foreach loop, verify if '$item["Created"]' is older than the cutoff, and execute 'Remove-PnPListItem -List $listName -Identity $item.Id -Force' to delete matched items.

Use PnP PowerShell to Filter and Delete Old Items
System Administrator Access: If you experience access denied errors, contact your system administrator to ensure your account has the correct site permissions and that the PnP Management Shell application is provisioned in your tenant.
Free Microsoft Office alternative

Manage Your Everyday Documents Effortlessly with WPS Office

While SharePoint and PowerShell handle complex enterprise server scripting, WPS Office provides a free, lightweight, and highly compatible alternative for everyday document, spreadsheet, and presentation management.

Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight installation with a familiar, easy-to-use tabbed user interface.Includes built-in PDF viewing and editing tools without requiring a premium subscription.Seamless migration for users looking for a reliable, cost-effective offline productivity suite.
microsoft office alternative - wps office

Frequently Asked Questions

How do I check if PnP PowerShell is already installed on my system?

Open your PowerShell terminal and type 'Get-Module -Name PnP.PowerShell -ListAvailable'. If the command returns module details, it is installed. Otherwise, you will need to install it using the Install-Module command.

Can I delete SharePoint items based on a custom date column instead of the default 'Created' date?

Yes. In the Get-PnPListItem command, specify your custom column's internal name in the -Fields parameter. Then, update your loop condition to compare '$item["YourCustomColumnName"]' against your defined cutoff date.

Are deleted SharePoint list items permanently removed immediately?

When you delete a list item using the Remove-PnPListItem command, it is typically sent to the SharePoint site's Recycle Bin. It can be restored by a site administrator within the standard retention period (usually 93 days) before it is permanently purged.

Why am I getting an 'Access Denied' error when running my PowerShell script?

This error usually occurs if your user account lacks sufficient permissions to delete items from the target SharePoint list, or if the PnP Management Shell Azure AD enterprise application has not been approved by your IT administrator.