如何使用PowerShell设置新SharePoint字段的内部名称?

我正在尝试将新字段添加到SharePoint列表并设置其内部名称.我同时指定了静态名称和显示名称,但我无法弄清楚为什么内部名称设置为First_x0020_Name.

$web = Get-SPWeb 'https://server'
$list = $web.Lists['listName']
$newFieldXML = '<Field Type="Text" StaticName="FirstName" DisplayName="First Name"></Field>'
$list.Fields.AddFieldAsXml($newFieldXML)
最佳答案
它看起来像AddFieldAsXml cannot be used to set the internal name

根据文章,如果您想使用AddFieldAsXml来设置您需要的内部名称:

  1. Define your CAML so that the Internal Name you want to use is
    actually set as the Display Name
  2. Create the field with the call to AddFieldAsXml
  3. After the field is created, retrieve it using the internal name and set the Title property to the real Display Name you wanted it to
    be in the first place

您还需要两个步骤:检索字段并设置内部名称

转载注明原文:如何使用PowerShell设置新SharePoint字段的内部名称? - 代码日志