Sep 26 2017 02:44 AM
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 taking -- any thoughts? Snippet of script below.
Many thanks.
$doclib = Get-PnPList -Identity "Quotes" -Includes RootFolder.UniqueContentTypeOrder $lct = $doclib.ContentTypes $ctx.Load($lct) $ctx.ExecuteQuery() $rootFolder = $doclib.RootFolder $lucto = $doclib.ContentTypes | ?{$_.Name -ne "<Content Type I'm Trying to Hide>"} $list = New-Object 'System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]' foreach ($i in $lucto) { $id = $i.Id $list.Add($id) } $rootFolder.UniqueContentTypeOrder = $list $rootFolder.Update() $doclib.Update()
Sep 26 2017 04:18 AM
Shouldn't you have
$ctx.ExecuteQuery()
at the end?
Haven't done this in powershell but the used method is the right one.
Sep 26 2017 04:23 AM
I don't think that there is an option for this in PnP PowerShell.
Sep 26 2017 07:13 AM
Oct 06 2021 06:44 AM
@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.