How to Delete Old SharePoint List Items Using PowerShell Script
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.

- 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.
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.
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.
Open your PowerShell terminal as an administrator and run 'Install-Module -Name PnP.PowerShell' if the module is not already installed on your system.
Run the connection command to authenticate with your site: 'Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive'.
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"'.
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.

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.

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.




