1

我有一个包含三列的内容类型“TestContentType”:

  • 文件类型
  • 类别
  • 子类别

此内容类型用于 3 个网站集中的 18 个文档库。

Category 列需要添加一个当前没有描述的“描述”。有没有办法通过脚本来实现这一点,所以我不必通过 UI 手动进行更改。

到目前为止,我已经提出了以下脚本,但到目前为止只列出了所有列表和文档库。我真正需要的是能够在这种情况下获取内容类型“TestContentType”,然后更新“Category”列以包含描述:

$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$webUrl = Read-Host -Prompt "HTTPS URL for the SP Online 2013 site" 
$username = Read-Host -Prompt "Email address login"
$password = Read-Host -Prompt "Password for $username" -AsSecureString


$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.ExecuteQuery()

$lists| select -Property Title

任何建议,将不胜感激。

4

1 回答 1

1

由于您必须更新内容类型中使用的网站栏, 因此可以使用Field.UpdateAndPushChanges 方法。它提交字段的更改属性并将更改传播到使用该字段的所有列表。

以下示例演示了如何更新字段Description并将此更改传播到所有列表:

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securedPassword)

$field = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$field.Description = $fieldDesc
$field.UpdateAndPushChanges($True)
$ctx.ExecuteQuery()

注意:必须为每个网站集执行指定的脚本。

于 2014-05-05T20:34:16.393 回答