Powershell Sharepoint Online - добавление типа контента в список - PullRequest
0 голосов
/ 03 февраля 2020

Я пытаюсь добавить тип контента в библиотеку документов в Sharepoint Online. Мой код ниже работает без ошибок, но тип контента не добавляется в библиотеку документов.

Есть идеи?

Спасибо P

#Bind to site collection  
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

#Get content types of the web
    $Context.Load($Context.Web.ContentTypes)
    $Context.ExecuteQuery()

    #Get the content type by its name
    $ContentType = $Context.Web.ContentTypes | Where {$_.Name -Match $newCT}
    $Context.Load($ContentType)   
    $Context.ExecuteQuery()

    #sharepoint online get content type id
    write-host -f Green "Content Type ID:" $ContentType.Id
    write-host -f Green "Content Type Title:" $ContentType.Name

    $List = $Context.Web.Lists.GetByTitle($DocLibName) 
    Write-host "List is " $DocLibName

    $Context.load($list)
    $Context.load($list.ContentTypes)
    $Context.ExecuteQuery()
    $list.ContentTypesEnabled=$true

    try{
        $addedContentType=$list.ContentTypes.AddExistingContentType($ContentType)
    }catch{
        write-host "ERROR!"
    }

    write-host -f Green "Added content type (" $newCT ") to list (" $DocLibName ")" 

    $list.Update()
``

1 Ответ

0 голосов
/ 03 февраля 2020

Кажется, мне не хватало этой части ...

        $context.ExecuteQuery()
...