แก้ไข SharePoint Online "การดำเนินการที่พยายามไม่ได้รับอนุญาตเนื่องจากเกินเกณฑ์มุมมองรายการที่บังคับใช้โดยผู้ดูแลระบบ" ใน PowerShell
ปัญหา: เมื่อพยายามรับรายการจากรายการ SharePoint Online ผ่าน PowerShell ฉันได้รับข้อความแสดงข้อผิดพลาด:
ข้อยกเว้นที่เรียก “ExecuteQuery” ด้วย อาร์กิวเมนต์ “0”: “การพยายามดำเนินการไม่ได้รับอนุญาต เนื่องจากเกินเกณฑ์มุมมองรายการที่บังคับใช้โดยผู้ดูแลระบบ”
At line:26 char:5
+ $Ctx.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException
จริงๆ แล้ว ฉันแค่พยายามลบรายการทั้งหมด:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/Sites/Projects"
$ListName="ProjectDocs"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the web and List
$Web=$Ctx.Web
$List=$web.Lists.GetByTitle($ListName)
#Get all items from the library
$Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Loop through each file in the library
Foreach($Item in $ListItems)
{
#Delete all Items
$List.GetItemById($Item.Id).DeleteObject()
}
$Ctx.ExecuteQuery()
Write-host -f Green "All Items deleted!"
สาเหตุหลัก: นี่เป็นเพราะว่าค่าเกณฑ์การควบคุมปริมาณทรัพยากรที่ฮาร์ดโค้ด 5000 บน SharePoint Online เกณฑ์มุมมองรายการช่วยให้แน่ใจว่าผู้ใช้ไม่ได้ดำเนินการราคาแพงบนสภาพแวดล้อม SharePoint Online ขออภัย เราไม่สามารถเปลี่ยนค่าขีดจำกัดนี้ได้เหมือนกับที่เราทำใน SharePoint On-Premises
โซลูชัน: ประมวลผลรายการเป็นชุดเพื่อแก้ไขปัญหาเกณฑ์มุมมองรายการ SharePoint Online ใน PowerShell
ดังนั้น เพื่อบรรเทาปัญหานี้ เราต้องประมวลผลสินค้าเป็นชุดงาน นี่คือสคริปต์ที่แก้ไขของฉัน ซึ่งจะลบรายการเป็นชุดเพื่อจัดการเกณฑ์มุมมองรายการ SharePoint Online ใน PowerShell
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$BatchSize = 500
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the web and List
$Web=$Ctx.Web
$List=$web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
Write-host "Total Number of Items Found in the List:"$List.ItemCount
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View Scope='RecursiveAll'><Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query><RowLimit Paged='TRUE'>$BatchSize</RowLimit></View>"
Do {
#Get items from the list in batches
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
Write-host Deleting $($ListItems.count) Items Starting from Item ID $ListItems[0].ID
#Loop through each item and delete
ForEach($Item in $ListItems)
{
$List.GetItemById($Item.Id).DeleteObject()
}
$Ctx.ExecuteQuery()
} While ($Query.ListItemCollectionPosition -ne $null)
Write-host -f Green "All Items Deleted!"
}
Catch {
write-host -f Red "Error Deleting List Items!" $_.Exception.Message
}
โปรดทราบว่าหากแบบสอบถาม CAML ของคุณดึงข้อมูลมากกว่า 5,000 แถว ก็จะยังคงล้มเหลว! เช่น หากคุณพยายามรับรายการทั้งหมด (ยกเว้น "โฟลเดอร์" โดยการระบุส่วนคำสั่ง "ที่ไหน") จากรายการขนาดใหญ่ที่สามารถส่งคืนได้มากกว่า 5,000 แถว คุณจะประสบปัญหาเกณฑ์การดูรายการ!
$Query.ViewXml = "@
<View Scope='RecursiveAll'>
<Query>
<Where>
<Eq>
<FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value>
</Eq>
</Where>
</Query>
<RowLimit Paged='True'>$BatchSize</RowLimit>
</View>"
สถานการณ์และแนวทางแก้ไขอื่นๆ
คุณอาจพบ “การดำเนินการที่พยายามถูกห้ามเนื่องจากเกินขีดจำกัดมุมมองรายการ” เมื่อดำเนินการ cmdlet ของรายการขนาดใหญ่ที่มีมากกว่า 5000 รายการ เช่น. เพิ่ม-PnPFile, คัดลอก-PnPFile, ค้นหา-pnpfile, รับ-pnpfolder, รับ-pnplist, วัด-pnplist, ย้าย-pnpfolder, ลบ-pnplist, เปลี่ยนชื่อ-pnpfolder หรือเมื่อคุณพยายามที่จะแยกการสืบทอด สร้างคอลัมน์จากการคำนวณ ลบรายการ รับรายการ แชร์ไฟล์ เปลี่ยนชื่อโฟลเดอร์ ฯลฯ
วิธีแก้ไข: คุณต้องลดจำนวนรายการในรายการหรือไลบรารีเอกสารโดยการย้ายหรือลบรายการออกจากไฟล์ที่ต่ำกว่า 5,000 รายการ
นี่คือบทความอื่นที่กล่าวถึงการอัปเดตรายการขนาดใหญ่ที่มีปัญหาเดียวกัน: SharePoint Online: รับรายการทั้งหมดจากรายการขนาดใหญ่โดยใช้ PowerShell โดยไม่มีมุมมองรายการเกินข้อผิดพลาด
