PnP powershell equivant - Hide content type from new menu

%3CLINGO-SUB%20id%3D%22lingo-sub-38414%22%20slang%3D%22en-US%22%3EPnP%20powershell%20equivant%20-%20Hide%20content%20type%20from%20new%20menu%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38414%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20method%20to%20hide%20content%20type%20from%20the%20'new'%20menu%20on%20a%20list%20in%20the%20same%20way%20using%20the%20UI%20located%20at%20_layouts%2F15%2FChangeContentTypeOrder.aspx.%20I%20have%20tried%20using%20following%20script%2C%20issue%20here%20is%20that%20it%20total%20hides%20the%20content%20type%20in%20the%20edit%20form%20%3A(%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24l%20%3D%20Get-PnPList%20-Identity%20%22lists%2FMyList%22-Web%20%24web%3CBR%20%2F%3E%24ctx%20%3D%20Get-pnpContext%3CBR%20%2F%3E%24ctx.Load(%24l.ContentTypes)%3CBR%20%2F%3E%24ctx.ExecuteQuery()%3C%2FP%3E%3CP%3Eforeach%20(%24ct%20in%20%24l.ContentTypes)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ct.Name%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(%24ct.Name%20-eq%20'ContentTypeName1')%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ct.Hidden%3D%24true%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ct.Update(%24false)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%24ctx.ExecuteQuery()%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-292831%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20powershell%20equivant%20-%20Hide%20content%20type%20from%20new%20menu%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-292831%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20do%20that%20with%20the%20following%20code%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EcontentTypeNamesInOrder%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%22Sub%20Project%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EcontentTypes%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EprojectInformationList%3C%2FSPAN%3E%3CSPAN%3E.ContentTypes%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Ectx%3C%2FSPAN%3E%3CSPAN%3E.Load%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EcontentTypes%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Ectx%3C%2FSPAN%3E%3CSPAN%3E.Load%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EprojectInformationList%3C%2FSPAN%3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3E%3CSPAN%3Ect%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EctList%3C%2FSPAN%3E%3CSPAN%3E.Add%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EctToInclude%3C%2FSPAN%3E%3CSPAN%3E.Id%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23Updating%20content%20type%20order%20and%20visibility%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EprojectInformationList%3C%2FSPAN%3E%3CSPAN%3E.RootFolder.UniqueContentTypeOrder%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EctList%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EprojectInformationList%3C%2FSPAN%3E%3CSPAN%3E.Update%3C%2FSPAN%3E%3CSPAN%3E()%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3EprojectInformationList%3C%2FSPAN%3E%3CSPAN%3E.RootFolder.Update%3C%2FSPAN%3E%3CSPAN%3E()%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3Ectx%3C%2FSPAN%3E%3CSPAN%3E.ExecuteQuery%3C%2FSPAN%3E%3CSPAN%3E()%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-38636%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20powershell%20equivant%20-%20Hide%20content%20type%20from%20new%20menu%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38636%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Rod%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eyou%20first%20need%20to%20add%20the%20new%20contenttype%20then%20change%20all%20items%20to%20the%20new%20contenttype%20end%20remove%20the%20contenttype.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethought%20i%20had%20some%20code%20but%20could%20not%20find%20it%20right%20now.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ekr%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPaul%3C%2FP%3E%3C%2FLINGO-BODY%3E
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

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()