【发布时间】: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