![](/img/trans.png)
[英]How can I get the “Copy Link” from a document on SharePoint Online document library using Powershell
[英]How can I setup default content type for a Document Library in SharePoint Online using PowerShell?
我正在开发一个 PowerShell 脚本,这个脚本应该执行以下任务:
我被困在第三点,无法使用 PowerShell 设置默认内容类型。 这是我用来更新内容类型的代码:
代码
$ctidary = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]
$ctidary.insert($ctID)
$list.rootfolder.uniquecontenttypeorder = $ctidary
$list.rootfolder.update()
$clientContext.executeQuery()
错误
Cannot find an overload for "insert" and the argument count: "1"
请建议我如何使用 Powershell 脚本将内容类型设置为 SharePoint Online 中文档库的默认内容类型。
提前致谢!
在我的方案中,以下解决方案适用于我的 SharePoint Online 租户:
$cttitle = "<Title of Content Type>"
$list = $clientContext.web.lists.GetByTitle("<Title of List/Library>")
$clientContext.load($list)
$clientContext.load($list.contenttypes)
$clientContext.executeQuery()
$currentOrder = $list.ContentTypes
$result = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]
foreach ($ct in $currentOrder)
{
if ($ct.Name.Contains($cttitle))
{
$result.Add($ct.Id)
}
}
$list.RootFolder.UniqueContentTypeOrder = $result
$list.RootFolder.Update()
$clientContext.executeQuery()
在这个解决方案中,当我尝试在$result
直接添加$ct
,它没有遍历所有内容类型,它对我不起作用,所以我遍历了所有内容类型并检索了内容类型的 ID。
这个怎么样?
$ctidary = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]
$ctidary.Add($ctID)
$list.RootFolder.UniqueContentTypeOrder = $ctidary
$list.RootFolder.Update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.