SharePoint Online: Nhận tất cả các mục danh sách với quyền duy nhất bằng PowerShell
Yêu cầu: Nhận tất cả các mục danh sách SharePoint Online với các quyền duy nhất bằng PowerShell.
Làm cách nào để kiểm tra xem một Mục trong danh sách có quyền duy nhất hay kế thừa quyền từ cấp độ gốc hay không?
Để biết liệu Mục hoặc Tệp trong danh sách SharePoint Online trong thư viện tài liệu có các quyền duy nhất hay không, hãy làm theo các bước sau:
- Điều hướng đến danh sách/thư viện rồi chọn mục danh sách.
- Từ ngăn chi tiết, nhấp vào liên kết “Quản lý quyền truy cập” (trong trải nghiệm Cổ điển, nhấp vào “Nâng cao” >> “Được chia sẻ với”) rồi nhấp vào liên kết “Nâng cao”.
Thao tác này sẽ đưa bạn đến trang Quyền nâng cao của mục danh sách, trang này cung cấp cho bạn thông tin về việc mục danh sách có quyền duy nhất hay đang kế thừa quyền từ cấp độ gốc. Ví dụ. Bạn sẽ nhận được văn bản “Mục danh sách này có quyền duy nhất”
SharePoint Online: PowerShell để lấy tất cả mục danh sách với các quyền duy nhất:
Hãy lấy tất cả các mục danh sách có quyền duy nhất bằng 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"
#Define Parameter values
$SiteURL="https://crescent.sharepoint.com/sites/PMO"
$ListName="Projects"
Try {
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get All Lists of the web
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
Write-host "Total List Items Found:"$List.ItemCount
#Query to Get 2000 items from the list
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View Scope='RecursiveAll'><RowLimit>2000</RowLimit></View>"
#Batch process list items - to mitigate list threshold issue on larger lists
Do {
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
#Loop through each List item
ForEach($ListItem in $ListItems)
{
$ListItem.Retrieve("HasUniqueRoleAssignments")
$Ctx.ExecuteQuery()
if ($ListItem.HasUniqueRoleAssignments -eq $true)
{
Write-Host -f Green "List Item '$($ListItem["Title"])' with ID '$($ListItem.ID)' has Unique Permissions"
}
else
{
Write-Host -f Yellow "List Item '$($ListItem["Title"])' with ID '$($ListItem.ID)' is inhering Permissions from the Parent"
}
}
} While ($Query.ListItemCollectionPosition -ne $null)
}
Catch {
write-host -f Red "Error Checking Unique Permissions!" $_.Exception.Message
}
Tìm các quyền duy nhất trong danh sách SharePoint Online bằng PnP PowerShell
Chúng tôi cũng có thể tìm kiếm các quyền duy nhất trong danh sách hoặc thư viện SharePoint Online bằng PnP PowerShell.
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName = "Projects"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get all list items in batches
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000
#Iterate through each list item
ForEach($ListItem in $ListItems)
{
#Check if the Item has unique permissions
$HasUniquePermissions = Get-PnPProperty -ClientObject $ListItem -Property "HasUniqueRoleAssignments"
If($HasUniquePermissions)
{
Write-Host -f Green "List Item '$($ListItem["Title"])' with ID '$($ListItem.ID)' has Unique Permissions"
}
Else
{
Write-Host -f Yellow "List Item '$($ListItem["Title"])' with ID '$($ListItem.ID)' is inhering Permissions from its Parent"
}
}
Làm theo tập lệnh trong bài viết này, bạn có thể dễ dàng truy xuất các mục từ danh sách SharePoint và lọc chúng để chỉ bao gồm các mục có quyền duy nhất được chỉ định. Để loại bỏ các quyền duy nhất khỏi tất cả các mục danh sách trong SharePoint Online, hãy sử dụng: SharePoint Online: Xóa các quyền duy nhất cho tất cả các mục trong danh sách bằng PowerShell
