【发布时间】:2015-09-25 01:02:38
【问题描述】:
我想使用 powershell 从 office 365 的列表中删除 Content-Type。我找到了这段代码,但 $Doclibrary 始终为空。
$lookForList = "Document"
$stringCTRemove = "Your Content type"
$docLibrary = $_.Lists[$lookForList]
if($docLibrary -ne $null)
{
$ctToRemove = $docLibrary.ContentTypes[$stringCTRemove]
write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
$docLibrary.ContentTypes.Delete($ctToRemove.Id)
$docLibrary.Update()
}
else
{
write-host "The list" $lookForList "does not exist in site" $_.Title
}
}
解决方案:
function removeBannersCT ($web)
{
$listName = "Banners"
$list = $context.Web.Lists.GetByTitle($listName)
$context.Load($list)
$context.ExecuteQuery()
$stringCTRemove = "Picture"
if($list -ne $null)
{
$lcontentTypes = $list.ContentTypes
$context.Load($lcontentTypes)
$context.ExecuteQuery()
foreach($cts in $lcontentTypes)
{
if($cts.Name -eq $stringCTRemove)
{
$list.ContentTypes.GetById($cts.Id).DeleteObject()
$list.Update()
write-host "Content-Type removed"
}
}
}
else
{
write-host "The list" $listName "does not exist in site"
}
}
拜托,你能帮帮我吗?我疯了!
提前致谢。
【问题讨论】:
-
已解决,我必须添加加载上下文。
标签: powershell sharepoint powershell-2.0 office365