0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

5000件超のリストで条件を指定してアイテムを削除する

Posted at

CamlQueryは5000件を超えると、RowLimitと条件を指定しても条件で絞り込まれずRowLimitも効かない。
→RowLimitで取得し、For文の中のIf文で条件で絞り込んで削除する。

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.credentials = $creds

try{
 $caml = "<View Scope='RecursiveAll'>
          <ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'></ViewFields>
          <Rowlimit Paged='TRUE'>5000</Rowlimit></View>"
 $list=$ctx.Web.Lists.GetByTitle("リスト表示名")
 $pagePosition = $null

 Do{
   $query = New-Object Microsoft.SharePoint.Client.CamlQuery
   $query.ListItemCollectionPosition = $pagePosition
   $query.ViewXml = $caml

   $listItems = $list.GetItems($query)
   $ctx.Load($listItems)
   $ctx.ExecuteQuery()

   $pagePosition = $listItems.ListItemCollectionPosition

   foreach($item in $listItems){
     if($item["Title"] -eq "削除したい値"){
       $listItems.GetById($item["ID"]).DeleteObject()
       $ctx.ExecuteQuery()
     }
   }
  until($pagePosition -eq $null)

 }
 catch{
       write-host "$($_.Exception.Message)" -foregroundcolor red    
}
$ctx.Dispose()

参考
stackexchange:Deleting over 5000 items SharePoint Online Powershell

SharePoint Online PowerShell 全アイテム削除

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?