简体   繁体   English

Powershell Sharepoint Online - 将内容类型添加到列表

[英]Powershell Sharepoint Online - Adding a content type to a list

I'm trying to add a Content Type to a Document Library within Sharepoint Online.我正在尝试将内容类型添加到 Sharepoint Online 中的文档库。 My code below runs with no errors but the Content Type doesn't get added to the Document Library.我下面的代码运行没有错误,但内容类型没有添加到文档库中。

Any ideas?有任何想法吗?

Thanks P谢谢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()
``

似乎我错过了这一部分......

        $context.ExecuteQuery()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SharePoint Online 和 PNP PowerShell - 在所有元数据中将库文档输出到 CSV,包括内容类型 - SharePoint Online & PNP PowerShell - output a libraries documents to CSV within all metadata, including CONTENT TYPE 如何使用 PowerShell 为 SharePoint Online 中的文档库设置默认内容类型? - How can I setup default content type for a Document Library in SharePoint Online using PowerShell? Powershell CSOM Sharepoint在线列表权限 - Powershell CSOM Sharepoint online list permission 在SharePoint Online中使用Powershell更改列表字段 - Change List Field with Powershell in SharePoint Online Scripto更新Sharepoint Online内容类型 - Scripto to update Sharepoint Online content type 如何通过powershell列出sharepoint在线目录中的文件 - How to list the files in a sharepoint online directory via powershell Powershell使用CSOM API从Sharepoint在线获取列表项 - Powershell get list items from Sharepoint online using CSOM API 如何使用PowerShell从Sharepoint Online列表中获取项目? - How to get items from a Sharepoint Online list using PowerShell? 通过PowerShell在Sharepoint Online中获取任务列表中的更改 - Get changes in a Task List in Sharepoint Online through PowerShell SharePoint Online Powershell CSOM从自定义模板创建列表 - SharePoint Online Powershell CSOM create list from custom template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM