Task
Hide Content type on SharePoint Online document library.
Solution
Requires PnP-Powershell, installation instructions here.
Connect-PnPOnline –Url “https://tenant.sharepoint.com”
$ctx = Get-PnPContext
$web = Get-PnPWeb
$doclib = Get-PnPList -Identity "<DOCLIBNAME>" -Includes ContentTypes,RootFolder.UniqueContentTypeOrder
$rootFolder = $doclib.RootFolder
$ct = $doclib.ContentTypes | where {$_.Name -eq "<CT TO BE HIDDEN>"}
$ct2 = $doclib.ContentTypes | where {$_.Name -eq "<CT TO BE HIDDEN, USUALLY FOLDER>"}
if($rootFolder.UniqueContentTypeOrder -eq $null)
{
$contentTypesInPlace = New-Object -TypeName 'System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]'
#$contentTypesInPlace = $doclib.ContentTypes | where {$_.Id -ne $ct.Id}
foreach($ct in $doclib.ContentTypes | where {$_.Id -ne $ct.Id -and $_.Id -ne $ct2.Id})
{
$contentTypesInPlace.Add($ct.Id)
}
}
else
{
$contentTypesInPlace = [System.Collections.ArrayList] $rootFolder.UniqueContentTypeOrder
$contentTypesInPlace = $contentTypesInPlace | where {$_.StringValue -ne $ct.Id}
}
#Set the UniqueContentTypeOrder to the collection we made above
$rootFolder.UniqueContentTypeOrder = [System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]] $contentTypesInPlace
#Update the root folder
$rootFolder.Update()
Execute-PnPQuery
No comments:
Post a Comment