1

I have a content type "TestContentType" with three columns:

  • Document Type
  • Category
  • Sub-category

This content type is used on 18 document libraries, in 3 site collections.

The Category column needs to have a "description" added which currently has no description. Is there a way to achieve this via a script so I don't have to make change manually via the UI.

So far I have come up with the following script, but this so far only lists all list and document libraries. What I actually need is to be able to get the content type in this case "TestContentType" and then update the "Category" column to include a description:

$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

Any suggestions would be appreciated.

1

Since you have to update site column used in Content Type, Field.UpdateAndPushChanges method could be utilized for that purpose. It commits changed properties of the field and propagates changes to all lists that use the field.

The following example demonstrates how to update field Description and propagate this change to all lists:

$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()

Note: The specified script have to be executed per every site collection.

  • 1
    Great thanks for this Vadim. I will do a quick test on dev tenant, but hopefully this should do it. – Dev P May 6 '14 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.