I want to delete items from a document library using powershell 2.0, but not all of them, only ones that pass some of my if statements (and no I can't use CAML for all my conditions). So I have to loop through the items and then delete it. Except it takes so long to delete all the items. So I want to use background jobs. I have this code:
$spListItem = .....; # I get the item here
$task = {
PARAM($spListItem);
$spListItem.Delete();
}
$job1 = Start-Job -ScriptBlock $task -ArgumentList $spListItem;
but this code is not working. Does anyone know what is wrong?
ERROR:
Method invocation failed because [Deserialized.Microsoft.SharePoint.SPListItem] doesn't contain a method named 'Delete'.
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound