Sharepoint Powershell - Delete all Items from a List on the Basis of Status

 This post is to explain the process of deleting all items from a list on the basis of the status (e.g. status= completed) using PowerShell script in Sharepoint.

To use the below script add your list/library name e.g. $docName=”<your list/library name>”
and your SharePoint site/web address e.g. $web = Get-SPWeb <your site/web address>

Script:
Add-PSSnapin Microsoft.SharePoint.PowerShell 
$web = Get-SPWeb <your site/web Url>
$docName="<list/library display name>"
$list = $web.lists | where {$_.title -eq $docName}

for($x=$list.ItemCount-1;$x -ge 0; $x--)
{
    
    $item=$list.Items[$x];
    
    if($item["Status"] -eq "COMPLETED")
    {
     Write-Host "Deleting item id" $item.ID
     $item.Delete();
    
           
    }

}
$list.Update();

Comments

Popular posts from this blog

Power Apps June 2023 Updates (Canvas App Focused)

Effortlessly Import JSON Data into SharePoint with Power Automate Flow: A Step-by-Step Guide

Unleash the Power of Power Apps: Retrieve Over 2000 Records from a SharePoint List Effortlessly Without Delegates