I want to delete list items from my CAML query but currently cannot using a foreach loop. What would be the best way to delete the items after the CAML query?
$Query = New-Object Microsoft.SharePoint.SPQuery
$Query.Query = "<Where><Leq><FieldRef Name='Created' /><Value Type='DateTime'><Today OffsetDays='-30' /></Value></Leq></Where><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>"
#Get List Items matching the query
$ListItems = $oList.GetItems($Query)
write-host "Number of items retrieved:" $ListItems.Count;
foreach($ListItem in $ListItems)
{
write-host "Deleting"+ $listItem.ID + $listItem.Name + $listItem["Created"];
#$ListItem.delete();
}