1

For the Library 'Site Pages' on communication Site, I need to change the order of the content type and set some of them to hide.

SetDefaultContentTypeToList for default content type for List 'Site Pages'

The issue was well known to see here : set default

so the proposed by the community is here: but doesn't hide content type in new button ,

 $doclib = Get-PnPList -Identity "<name of your doclib>" -Includes ContentTypes, RootFolder.UniqueContentTypeOrder
$rootFolder = $doclib.RootFolder
$contentTypeToHide = Get-PnPContentType -List $doclib -Identity "<name of the ct to hide>";
$list = New-Object 'System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]'
foreach ($i in $rootFolder.UniqueContentTypeOrder) {
    if($i.StringValue -ne $contentTypeToHide.StringId)
    {
        $list.Add($i)
    }
}
$rootFolder.UniqueContentTypeOrder = $list
$rootFolder.Update()
$doclib.Update()
Execute-PnPQuery
1

Check the PowerShell below.

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

Refer to: SharePoint Online: Hide content type on list

  • Execute-PnPQuery + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-PnPQuery], ServerException – Imen Turki Mar 29 at 7:02
  • thank you , this solution works for others libraries but not for 'site Pages" , so i do it with csomPowershell – Imen Turki Mar 31 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.