In this article you can able
to see how to delete SharePoint list
items based on the particular view and also having another condition how have
to delete items on every Monday, we created a couple of views what type of data
have to delete based on item created date.
One view is used to delete
SharePoint list items every day and another delete only on Monday.
Note: by default list item limit is 30 items, we
have to modify the view based on the requirement I change to 5000 so every day
it will delete only 5000 items to delete.
add-pssnapin
microsoft.sharepoint.powershell
$web = get-spweb -identity
"http://dotnetsharepoint.com/sites/sharepoint/deleteitems"
$MainList =
$web.lists["DeleteListItems"];
$today =
(get-date).DayOfWeek
if($today -eq
"Monday")
{
$view = $MainList.Views["DeleteMondaylistitems"];
}
else
{
$view =
$MainList.Views["DeleteEverydaylistitems"];
}
$items =
$MainList.GetItems($view)
$totalcount = $items.Count
$j = 0;
for($i = $totalcount -1; $i
-ge 0; $i--)
{
$deleteitem = $items[$i]
write-host $deleteitem.ID
$deleteitem.Delete()