Powershell Sharepoint Online - 将内容类型添加到列表
Powershell Sharepoint Online - Adding a content type to a list
我正在尝试将内容类型添加到 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()
``
我好像漏掉了这部分...
$context.ExecuteQuery()
我正在尝试将内容类型添加到 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()
``
我好像漏掉了这部分...
$context.ExecuteQuery()