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

[玩转系统] 使用 PowerShell 获取 SharePoint Online 中列的内部名称

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

使用 PowerShell 获取 SharePoint Online 中列的内部名称


要求:使用 PowerShell 获取 SharePoint Online 列表列的内部名称。

如何获取SharePoint Online中的内部字段名称?

正如我的另一篇文章中所述:SharePoint 字段显示名称与内部名称,当您在 SharePoint 中创建新列时,您为其指定一个“标题”,该标题将成为“显示名称”。 SharePoint 通过使用 Unicode 编码替换所有特殊字符和空格,自动从显示名称分配内部名称。字段可以具有相同的内部名称或与其显示名称不同的名称(例如,“创建者”字段的内部名称是:作者!)。即使您更改字段的标题,此内部名称也保持静态。有时,您可能需要列的内部名称来检索 SharePoint 中的字段值。

以下是如何在 SharePoint Online 列表中查找字段的内部名称:

  1. 导航到列表或文档库 >> 单击设置 >> 列表设置。
  2. 在“Column”部分下,单击任意列,您可以从 Field 参数值中获取 URL 中的列内部名称。例如。就我而言,它是:“Project_x0020_Classification”

    [玩转系统] 使用 PowerShell 获取 SharePoint Online 中列的内部名称

您还可以对列进行排序并从 SortField 参数值获取内部名称。

[玩转系统] 使用 PowerShell 获取 SharePoint Online 中列的内部名称

是否可以更改 SharePoint Online 中的列内部名称?答案是不!您无法更改 SharePoint 中字段的内部名称。唯一的解决方法是:删除并重新创建该列。

SharePoint Online:用于获取内部字段名称的 PowerShell

如果您需要在代码或其他脚本中引用该列,这个方便的 PowerShell 脚本可以帮助您获取该列的内部名称。让我们从 SharePoint Online 中的显示名称获取字段的内部名称:


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName ="Projects"
$FieldTitle = "Project Classification"

#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 and field
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Field =  $List.Fields.GetByTitle($FieldTitle)
$Ctx.Load($Field)
$Ctx.ExecuteQuery()

         
#PowerShell to get internal name of sharepoint online list column
Write-Host $Field.InternalName
最好首先创建一个没有空格或特殊字符的列,这样字段内部名称就会整洁干净,然后根据需要使用任何特殊字符或空格更改字段的标题!

SharePoint Online:用于获取内部字段名称的 PnP PowerShell

这次,我们使用 PnP PowerShell 从 SharePoint Online 列表中获取所有字段的内部字段名称。


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName ="Projects"
$FieldTitle = "Project Classification"

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

#Get the list column
Get-PnPField -Identity $FieldTitle -List $ListName | Select InternalName

获取列表中所有字段的内部名称怎么样?


#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName ="Projects"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    
    #Get list column internal names
    Get-PnPField -List $ListName
}
Catch {
    Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

若要从 SharePoint Online 列表中获取所有字段,请使用:SharePoint Online:使用 PowerShell 获取所有列表字段

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

取消回复欢迎 发表评论:

关灯