PnP powershell equivant - Hide content type from new menu

Highlighted
New Contributor

Is there a method to hide content type from the 'new' menu on a list in the same way using the UI located at _layouts/15/ChangeContentTypeOrder.aspx. I have tried using following script, issue here is that it total hides the content type in the edit form :(

 

$l = Get-PnPList -Identity "lists/MyList"-Web $web
$ctx = Get-pnpContext
$ctx.Load($l.ContentTypes)
$ctx.ExecuteQuery()

foreach ($ct in $l.ContentTypes)
{
    $ct.Name
    if ($ct.Name -eq 'ContentTypeName1')
    {
        $ct.Hidden=$true
        $ct.Update($false)
    }

}

$ctx.ExecuteQuery()

 

Regards...

 

2 Replies
Highlighted

Hi Rod,

 

you first need to add the new contenttype then change all items to the new contenttype end remove the contenttype.

 

thought i had some code but could not find it right now.

 

kr,

 

Paul

Highlighted

You can do that with the following code:

$contentTypeNamesInOrder = "Sub Project"
$contentTypes = $projectInformationList.ContentTypes
$ctx.Load($contentTypes)
$ctx.Load($projectInformationList.RootFolder)
$ctx.ExecuteQuery()

$ctList = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]
Foreach($ct in $contentTypeNamesInOrder){
$ctToInclude = $contentTypes | Where-Object {$_.Name -eq $ct}
$ctList.Add($ctToInclude.Id)
}
#Updating content type order and visibility
$projectInformationList.RootFolder.UniqueContentTypeOrder = $ctList
$projectInformationList.Update()
$projectInformationList.RootFolder.Update()
$ctx.ExecuteQuery()