当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 获取列表字段属性

作者:精品下载站 日期:2024-12-14 14:38:28 浏览:16 分类:玩电脑

SharePoint Online:使用 PowerShell 获取列表字段属性


要求:使用 PowerShell 获取 SharePoint Online 中的列表字段设置。

PowerShell 用于获取 SharePoint Online 中的字段属性

此 PowerShell 脚本可从 SharePoint Online 列表字段获取常见属性:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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 从 SharePoint Online 列表获取列设置

使用 PnP PowerShell 中的 Get-PnPField cmdlet 获取字段及其属性:


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

要获取字段(或任何对象)的所有可用属性值,请使用以下命令:


$Field | Select -Property *

通过使用这些脚本,您可以使用 PowerShell 轻松获取 SharePoint Online 中的列设置。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯