Tìm kiếm trang web

SharePoint Online: Nhận thuộc tính trường danh sách bằng PowerShell


Yêu cầu: Nhận cài đặt trường danh sách trong SharePoint Online bằng PowerShell.

PowerShell để lấy thuộc tính trường trong SharePoint Online

Tập lệnh PowerShell này cung cấp cho bạn các thuộc tính chung từ trường danh sách SharePoint Online:


#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"

#Set Config Parameters
$SiteURL="https://crescent.sharepoint.com/sites/projects"
$ListName="PMO Projects"
$FieldName="HeadCount" #Internal Name

#Get Credentials to connect
$Cred= Get-Credential

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Get the List
$List=$Ctx.Web.Lists.GetByTitle($ListName)

#Get the List Field
$Field=$List.Fields.GetByInternalNameOrTitle($FieldInternalName)
$Ctx.Load($Field)
$Ctx.ExecuteQuery()

#Get List Field Settings
Write-host "Title:"$Field.Title
Write-host "Description:"$Field.Description
Write-host "Default Value:"$Field.DefaultValue
Write-host "Unique Values:"$Field.EnforceUniqueValues
Write-host "Is Hidden:"$Field.Hidden
Write-host "Field ID:"$Field.Id
Write-host "Indexed:"$Field.Indexed
Write-host "InternalName:"$Field.InternalName
Write-host "Required Field:"$Field.Required
Write-host "Sortable:"$Field.Sortable
Write-host "Filterable:"$Field.Filterable
Write-host "Type:"$Field.TypeAsString
Write-host "Type Display Name:"$Field.TypeDisplayName
Write-host "Sealed:"$Field.Sealed
Write-host "Can Be Deleted:"$Field.CanBeDeleted
Write-host "Read Only Field:"$Field.ReadOnlyField
Write-host "Group:"$Field.Group
Write-host "Field Scope:"$Field.Scope
Write-host "JSLink:"$Field.JSLink
Write-host "Schema XML:"$Field.SchemaXML
Write-host "Validation Formula:"$Field.ValidationFormula
Write-host "Validation Message:"$Field.ValidationMessage

PnP PowerShell để nhận cài đặt cột từ danh sách SharePoint Online

Sử dụng lệnh ghép ngắn Get-PnPField trong PnP PowerShell để lấy trường và các thuộc tính của nó:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/pmo"
$ListName = "Projects"
$ColumnName = "Status" #Internal Name

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get the Field
    $Field = Get-PnPField -List $ListName -Identity $ColumnName
    
    #Get properties of the Field
    $Field | Select Title, ID, TypeAsString, Required
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Để có được tất cả các giá trị thuộc tính có sẵn của tệp (hoặc bất kỳ đối tượng nào), hãy sử dụng như sau:


$Field | Select -Property *

Bằng cách sử dụng các tập lệnh này, bạn có thể dễ dàng nhận được cài đặt cột trong SharePoint Online bằng PowerShell.

Bài viết liên quan