【问题标题】:How do I add an existing People Picker Column to a Content Type using PowerShell?如何使用 PowerShell 将现有人员选取器列添加到内容类型?
【发布时间】:2021-11-11 08:46:23
【问题描述】:

我正在尝试使用 PowerShell 将现有的人员选取器站点列添加到现有的内容类型。

我有以下脚本尝试添加字段失败,因为它是错误的类型

$url = "xyz"
$Web = Get-SPWeb $url
AddColumnToContentType "Username" "CTLog"

function AddColumnToContentType($columnname, $contenttypename){
$ContentTypeColl = $Web.ContentTypes
$ContentType = $ContentTypeColl | Where {$_.Name -eq $contenttypename}
If($ContentType -eq $Null)
{
Write-host "Content Type '$ContentTypeName' doesn't exist" -f Yellow
Return
}
$SiteColumnColl = $Web.Fields
$SiteColumn = $SiteColumnColl | Where {$_.Title -eq $columnname}
if($SiteColumn -eq $Null)
{
Write-host "Site Column '$SiteColumnName' doesn't exists!" -f Yellow
Return
}
$FieldCollection = $ContentType.Fields
$Field = $FieldCollection | Where {$_.Title -eq $columnname}
if($Field -ne $Null)
{
Write-host "Site Column '$SiteColumnName' Already Exists in the content type!" -f Yellow
Return
}
$FieldLink = New-Object Microsoft.SharePoint.Client.FieldLinkCreationInformation
$FieldLink.Field = $SiteColumn
[Void]$ContentType.FieldLinks.Add($FieldLink)
$ContentType.Update($true)

这是错误

异常设置“字段”:“无法将类型“Microsoft.SharePoint.SPFieldUser”的“用户名”值转换为类型“Microsoft.SharePoint.Client.Field”。

非常感谢您的建议

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    它必须是 Microsoft.SharePoint.SPFieldLink 而不是 Microsoft.SharePoint.Client.FieldLinkCreationInformation

    $FieldLink = New-Object Microsoft.SharePoint.SPFieldLink($SiteColumn)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      相关资源
      最近更新 更多