我在 SharePoint Online 的 SharePoint 加载项中有一个列表列,它是一个多行富文本字段。我想使用 Power-Shell 将其转换为增强富文本字段。
$URL、$Username、$password 和 $ListTitle 作为参数传递给编写此代码的函数。
try
{
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
$ll=$ctx.Web.Lists.GetByTitle($ListTitle)
$ctx.Load($ll)
$ctx.ExecuteQuery()
#Add new field to the list
Write-Host "`nGot List" $ListTitle
$fieldColl = $ll.Fields;
$isDescriptionPlainText = $false;
$ctx.Load($fieldColl);
$ctx.ExecuteQuery();
foreach ($item in $fieldColl)
{
if($item.InternalName -eq "VisualDescription")
{
if($item.InternalName -eq "VisualDescription" -and $item.RichText -eq $false)
{
Write-Host ("`n'{0}' Field available.Making Rich Text"-f $item.InternalName)
$msg=("`n'{0}' Field available.Making Rich Text"-f $item.InternalName)
writeToLog $msg
$isDescriptionPlainText=$true;
$item.RichText = $true
$item.update()
}
else
{
Write-Host ("`n Field not available or already a rich text.")
$msg=("Field not available or already a rich text.")
writeToLog $msg
}
}
}
if($isDescriptionPlainText)
{
$ll.update()
$ctx.Load($ll)
$ctx.ExecuteQuery()
}
}
catch
{
$errorMessage = $_.Exception.Message
$errLineNumber = $_.InvocationInfo.ScriptLineNumber
$errOffset = $_.InvocationInfo.OffsetInLine
$msg = "The script failed due to an unexpected error. [Reason]: $errorMessage [Error Line Number]: $errLineNumber ($errOffset)"
writeErrorToLog $msg
# Log the entire stack trace
writeErrorToLog $_.Exception
Write-Error $msg
}
我不能使用$item.RichTextMode = "FullHtml"
,因为RichTextMode
属性不存在$item