function Get-SPList($webUrl, $lstUrl)
{
$webObj = Get-SPWeb -identity $webUrl
$lstObj = $webObj.GetList($lstUrl);
return $lstObj
}
$spList = Get-SPList -webUrl "http://mysitecollecton/MySite" -lstUrl "http://mysitecollecton/MySite/Lists/EmpInfo"
$spQuery = new-object Microsoft.SharePoint.SPQuery
$camlQuery =
"<Where>
<Eq>
<FieldRef Name='Department' />
<Value Type='Text'>HR</Value>
</Eq>
</Where>"
$spQuery.Query = $camlQuery
$spQuery.RowLimit = 100
$spListItemCollection = $spList.GetItems($spQuery)
$spListItemCollection | ForEach-Object {
$_["Description"] = "Hi there..."
$_.Update()
}
=============================================================================================
function Get-SPList($webUrl, $lstUrl)
{
$webObj = Get-SPWeb -identity $webUrl
$lstObj = $webObj.GetList($lstUrl);
return $lstObj
}
$spList = Get-SPList -webUrl "http://mysitecollecton/MySite" -lstUrl "http://mysitecollecton/MySite/Lists/EmpInfo"
$spQuery = new-object Microsoft.SharePoint.SPQuery
$camlQuery =
"<Where>
<Eq>
<FieldRef Name='Department' />
<Value Type='Text'>HR</Value>
</Eq>
</Where>"
$spQuery.Query = $camlQuery
$spQuery.RowLimit = 100
$spListItemCollection = $spList.GetItems($spQuery)
# Create batch remove CAML query
$batchRemove = '<?xml version="1.0" encoding="UTF-8"?><Batch>';
# The command is used for each list item retrieved
$command = '<Method><SetList Scope="Request">' +
$spList.ID +'</SetList><SetVar Name="ID">{0}</SetVar>' +
'<SetVar Name="Cmd">Delete</SetVar></Method>';
foreach ($item in $spListItemCollection)
{
$batchRemove += $command -f $item.Id;
}
$batchRemove += "</Batch>";
# Remove the list items using the batch command
$spList.ParentWeb.ProcessBatchData($batchRemove) | Out-Null
==========================================================================================
Thnaks to "http://adicodes.com/update-delete-copy-list-items-with-powershell-in-sharepoint-2010/"
No comments:
Post a Comment