SharePoint Online: Nhận cài đặt danh sách bằng PowerShell
Yêu cầu: Nhận cài đặt danh sách SharePoint Online bằng PowerShell.
Làm cách nào để lấy thuộc tính danh sách trong SharePoint Online?
Để nhận các thuộc tính danh sách như Tiêu đề danh sách, Mô tả, Cài đặt phiên bản, Yêu cầu kiểm tra, v.v., bạn có thể đi tới trang cài đặt Danh sách.
SharePoint Online: PowerShell để lấy thuộc tính danh sách
Bạn có thể lấy thuộc tính danh sách của danh sách SharePoint Online bằng tập lệnh PowerShell này. Tất cả những gì bạn cần làm là mở PowerShell và kết nối với trang SharePoint Online của mình. Sau đó, sử dụng tập lệnh sau để lấy thuộc tính danh sách:
#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"
#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 List
$List=$Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Get List Properties: Title, Description
Write-host -f Yellow "--- General Settings ---"
Write-host "List Title:" $List.Title
Write-host "List Description:" $List.Description
#Write-host "Show in Quick Launch:" $List.OnQuickLaunch
Write-host -f Yellow "--- Versioning settings ---"
Write-host "Content Approval Enabled:" $List.EnableModeration
Write-host "Versioning Enabled:" $List.EnableVersioning
Write-host "Major Versions Limit:" $List.MajorVersionLimit
#Write-host "Minor Versions Enabled:" $List.EnableMinorVersions
Write-host "Minor Versions Limit:" $List.MajorWithMinorVersionsLimit
Write-host "Draft Versions Security:" $List.DraftVersionVisibility
Write-host "Require Checkout:" $List.ForceCheckout #In Document Libraries
Write-host -f Yellow "--- Advanced settings ---"
Write-host "Content Type Enabled:"$List.ContentTypesEnabled
Write-host "Attachments Enabled:"$List.EnableAttachments
Write-host "New Folders Command Available:"$List.EnableFolderCreation
Write-host "No Crawl Flag:"$List.NoCrawl
#Write-host "Offline Availability:"$List.ExcludeFromOfflineClient
Write-host "List Experience:"$List.ListExperienceOptions
#Other hidden Settings
Write-host -f Yellow "--- Other settings ---"
Write-host "List ID:"$List.ID
Write-host "List Created On:"$List.Created
Write-host "Last Item Deleted On:"$List.LastItemDeletedDate
Write-host "Last Item Modified On:"$List.LastItemModifiedDate
Write-host "List Item Count:"$List.ItemCount
Write-host "Is Hidden List:"$List.Hidden
Write-host "Document Template:"$List.DocumentTemplateUrl #In Document Libraries
Write-host "List Type:"$List.BaseType
}
Catch {
write-host -f Red "Error Getting List Properties!" $_.Exception.Message
}
Sử dụng tập lệnh này để lấy tất cả các thuộc tính từ danh sách:
$List | select -Property *
Lệnh này sẽ trả về danh sách tất cả các thuộc tính cho danh sách. Xin lưu ý, không phải tất cả thuộc tính danh sách đều có thể được truy xuất hoặc đặt thông qua CSOM! Đây là One-liner để truy xuất tất cả các thuộc tính có sẵn của danh sách hoặc thư viện SharePoint Online:
$List | Select -Property ([Microsoft.SharePoint.Client.List].GetProperties().Where({$_.Propertytype -notlike "*Collection"})).Name
Chúng tôi đã lọc các thuộc tính bộ sưu tập vì mọi bộ sưu tập đều phải được tải rõ ràng trước rồi mới có thể truy cập được!
PnP PowerShell để lấy thuộc tính danh sách
Một cách tiếp cận khác là sử dụng lệnh ghép ngắn Get-PnPList. Trước tiên, bạn phải kết nối với SharePoint Online bằng lệnh ghép ngắn Connect-PnPOnline để sử dụng lệnh ghép ngắn này. Sau khi kết nối, bạn có thể chạy lệnh ghép ngắn Get-PnPList và chỉ định Tên của danh sách mà bạn muốn lấy thông tin.
PnP PowerShell có thể được sử dụng để truy xuất các thuộc tính danh sách, bao gồm URL, tiêu đề, mô tả, số lượng mục, v.v. Ví dụ: để lấy số lượng mục trong danh sách, hãy sử dụng lệnh Get-PnPList -Identity | Chọn Đếm vật phẩm. Hãy chắc chắn thay thế nó bằng tên thực của danh sách.
#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Announcements"
#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive
#Get List
$List = Get-PnPList -Identity $ListName
#Get List Properties
Write-host "Versioning Enabled:"$List.EnableVersioning
Để nhận bất kỳ thuộc tính nào thuộc loại "bộ sưu tập", hãy sử dụng tham số "bao gồm". Ví dụ.,
#Get the List with "Author" property
$List = Get-PnPList -Identity $ListName -Includes Author
Invoke-PnPQuery
#Get the Login ID of the user created the List
Write-host "List Author:"$List.Author.LoginName
Để cập nhật cài đặt danh sách trong SharePoint Online bằng PowerShell, hãy sử dụng: Cách cập nhật cài đặt danh sách SharePoint Online bằng PowerShell?
