Pnp-powershell: Cannot disable "Visible On New Button" for Content Type on Document Library

Created on 26 Sep 2017  路  1Comment  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

Please confirm what it is that your reporting

Issue

Expected behavior

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

Actual behavior

Please describe what you see instead. Please provide samples of HTML output or screenshots

The values don't get set and nothing changes.

Steps to reproduce behavior

Please include complete code samples in-line or linked from gists

  • Create a new document library
  • Turn on Content Types
  • Add a new content type
  • Try to turn off visibility programmatically.

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [X] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

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

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [X] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

Most helpful comment

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

>All comments

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
Was this page helpful?
0 / 5 - 0 ratings