Kashif Nizam Qureshi

Leave a comment

Deleting List Items Through PowerShell Filtered Using CAML Query

Use the following to delete items older than the specified date in CAML below and limiting to 500 all together.

$site = new-object Microsoft.SharePoint.SPSite("<a href="http://dhldepmweb01/PWA">http://dhldepmweb01/PWA</a>")

$web = $site.rootweb

$list = $web.Lists["Project Server Workflow Tasks"]



<FieldRef Name="Created" />

<Value IncludeTimeValue="TRUE" Type="DateTime">2015-12-31T02:32:20Z</Value>



$query=new-object Microsoft.SharePoint.SPQuery

$query.Query=$caml | Write-Output


$listItemsTotal = $items.Count;


#Limiting the deletion till 500 count

for($x=$listItemsTotal-1;$x -ge 0 -And $count -le 500; $x--)







Leave a comment

Adding Resource Calendar Exceptions Programmatically

ResourceDataSet rds = _resourceClient.ReadResource(new Guid(resGuid));

// be sure that the resource is checked out !

if (rds.CalendarExceptions != null)
for (int i = 0; i &lt; rds.CalendarExceptions.Rows.Count; i++)
// check row data...

// delete row if necessary
// don´t use GetChanges() method on the dataset !
_resourceClient.UpdateResources(resourceDataSet, false, false);

// Read resource data again
rds = _resourceClient.ReadResource(new Guid(resGuid));

// create new datarow
ResourceDataSet.CalendarExceptionsRow exceptionsRow = rds.CalendarExceptions.NewCalendarExceptionsRow();

// set necessary data for the new exception row here

// update the resource again
_resourceClient.UpdateResources(resourceDataSet, false, false);

// don´t forget to check in the resource