Please confirm what it is that your reporting
Issue
Please describe what output you expect to see from PnP-PowerShell Cmdlets
I'm trying to switch "Visible on New Button" off for a Content Type on a list. I've already enabled the list for content types and added a content type, but don't want it to appear on the "New" button.
I've tried various ways and it doesn't appear to have any effect. Specifically I'm trying to set the UniqueContentTypeOrder which looks like what I need.
Partial script as follows:
$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()
Please describe what you see instead. Please provide samples of HTML output or screenshots
The values don't get set and nothing changes.
Please include complete code samples in-line or linked from gists
(you can retrieve this by executing Get-Module -Name *pnppowershell* -ListAvailable)
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.18.17... SharePointPnPPowerShellOnline {Add-PnPClientSidePage, Add-PnPClientSidePageSection, A...
Binary 2.14.17... SharePointPnPPowerShellOnline {Add-PnPContentType, Add-PnPContentTypeToDocumentSet, A...
Close, but not complete :-)
This does it:
$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
Most helpful comment
Close, but not complete :-)
This does it: