Forum Discussion
Darren Parkinson
Sep 26, 2017Brass Contributor
Can't turn off "Visible on New Button" for Content Type using PnP PowerShell
Hi, I'm having trouble turning off the "Visible on New Button" option for a Content Type on a Document Library. I'm trying to use the "UniqueContentTypeOrder" to do that. So far, it's not ...
nfsg20
Oct 06, 2021Copper Contributor
Darren Parkinson Try Invoke-PnPQuery, you dont need to use ctx at all.
Working Code for me (I'm using the opposite approach, telling the function what content type I want to have in the "New" menu):
function SetVisibleContentType($listName, $ctName) {
$ct = Get-PnPContentType -List $listName -Identity $ctName
$list = Get-PnPList -Identity $listName -Includes RootFolder.UniqueContentTypeOrder
$idList = New-Object "System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]"
$idList.Add($ct.Id)
$list.RootFolder.UniqueContentTypeOrder = $idList
$list.RootFolder.Update()
Invoke-PnPQuery
}
If you want to show more than one content type, just pass a string-array of content type names, or change the logic to show all but the provided conten type name.