0

I have stack list now i want delete my list item corresponding the date and time.what are all the ways to delete list item. I used power-shell for particular list

$web = get-spweb -Identity http://sitename
$list = $web.lists["list name"]
$list.AllowDeletion = $true
$list.Update()
$list.Delete()

1 Answer 1

0

If you want to delete a list item then first you need to get the corresponding item. For that you can use CAML query and pass the date time parameter

$list = $rootWeb.Lists.TryGetList($ListName);
$isoDeleteItemsDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now); #change it to date of your preference

$camlQueryString = [String]::Format("<Where><Eq><FieldRef Name='DateTimeFieldName' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{0}</Value></Leq></Where>", $isoDeleteItemsDate);
$camlQuery = New-Object -TypeName "Microsoft.SharePoint.SPQuery" -ArgumentList @($list.DefaultView);
$camlQuery.Query=$camlQueryString;

$camlResults = [Microsoft.SharePoint.SPListItemCollection] $list.GetItems($camlQuery);
$listItems = [System.Data.DataTable]$camlResults.GetDataTable();
foreach($listItemRow in $listItems.Rows)
{
    $listItemIdToDelete = $listItemRow["ID"];
    $listItemToDelete = $listToProcess.GetItemById($listItemIdToDelete);
    $listItemToDelete.Delete();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.