Bulk delete Items from SharePoint list
Applies to: SharePoint Online & On-premises
Description:
This article describes steps to delete items from Sharepoint list. If there are many items in list and you only want to keep some of them then based on the ID value items can be deleted.
SharePoint Online
Pre-requisites:
1. SharePoint Online Management Shell (link to download: https://www.microsoft.com/en-in/download/details.aspx?id=35588) and SharePoint Client Components SDK (https://www.microsoft.com/en-in/download/details.aspx?id=42038)
2. Install both of the above components in your machine (Run as Administrator)
3. To delete the items from send mails list you need “Contribute” permissions on the list
4. Script File to delete items (DeleteItems.ps1). Download DeleteItemsScript_Online. Extract the zip file and find the “DeleteItems.ps1” script file.
Updates to Script File:
1. Open DeleteItems.ps1 and replace place holders with Site URL, List Name, User Name and Password.
- [Site URL]
- [List Name]
- [User Name]
- [Password]
2. Change $StartItemId and $EndItemId as per the ID range of items to delete. You can add ID column to the list view and sort the view by ID from highest to lowest to see the current maximum ID value. Similarly you can find the minimum value as well. Based on current max Id, you can decide how many to keep and then accordingly set the values for these variables:
How to Run:
Run “SharePoint Online Management Shell” as administrator and type command
Command: “. ‘[File Path]’”
Example: . ‘C:\ DeleteItems.ps1’
Screenshot:
SharePoint On-premises
Steps:
1. Download DeleteItemsScript_OnPrem. Extract the zip file and find the DeleteItems.ps1 script file.
2. Open delete items script file and modify the “SiteURL” and “ListName” placeholders in delete items script file and save the file (see screenshot below)
3. Copy the delete items script file to the SharePoint server
4. Right click “DeleteItems.ps1” file and click “Run with Powershell”