Start-Transcript -path C:\output.txt -append
$SiteUrl ="Site url"
$list = (Get-Spweb "$SiteUrl").GetList("$SiteUrl"+/Lists/ListTitle/)
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000;
$query.Query = '<Where><Leq><FieldRef Name="Created"/><Value Type="DateTime" IncludeTimeValue="TRUE">YYYY-MM-DDT00:00:00Z</Value></Leq></Where>';
#$query.Query = '';
$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" );
Write-Host "before do while "
Get-Date
do
{
$listItems = $list.GetItems($query)
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach ($item in $listItems)
{
if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++; write-host "Created on " $item["Created"] $itemCount }
}
}
while ($query.ListItemCollectionPosition -ne $null)
$batchXml.Append("</Batch>");
$itemCount;
Write-Host "after do while "
Get-Date
#And lastly (and most importantly!), run the query
#Write-Host "Batch process started "
#Get-Date
#$web = Get-Spweb $SiteUrl;
#$web.ProcessBatchData($batchXml.ToString()) | Out-Null;
#Write-Host "Batch process end"
#Get-Date
Stop-Transcript
$SiteUrl ="Site url"
$list = (Get-Spweb "$SiteUrl").GetList("$SiteUrl"+/Lists/ListTitle/)
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000;
$query.Query = '<Where><Leq><FieldRef Name="Created"/><Value Type="DateTime" IncludeTimeValue="TRUE">YYYY-MM-DDT00:00:00Z</Value></Leq></Where>';
#$query.Query = '';
$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" );
Write-Host "before do while "
Get-Date
do
{
$listItems = $list.GetItems($query)
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach ($item in $listItems)
{
if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++; write-host "Created on " $item["Created"] $itemCount }
}
}
while ($query.ListItemCollectionPosition -ne $null)
$batchXml.Append("</Batch>");
$itemCount;
Write-Host "after do while "
Get-Date
#And lastly (and most importantly!), run the query
#Write-Host "Batch process started "
#Get-Date
#$web = Get-Spweb $SiteUrl;
#$web.ProcessBatchData($batchXml.ToString()) | Out-Null;
#Write-Host "Batch process end"
#Get-Date
Stop-Transcript