1

I generally do all of my programmatic stuff using SharePoint PNP, but adding a content type to a list in a subsite does not show the content type as visible on the new button.

Because of this, I am looking to show it via code. I don't usually do this so looking for some help. So far I have this:

Connect-PnpOnline -Url $url -Credentials $creds
$ctx = Get-PnpContext
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$list = $ctx.Web.Lists.GetByTitle("My List Name")
$ctx.Load($List)
$ctx.ExecuteQuery()
$ct = Get-PnpContentType -List "My List Name" -Identity "My Content Type Name"
$ctid = $ct.id.StringValue

This is where I get stuck. Can't really find anything that does what I am trying to do. Basically I want to just do $contentType.Hidden = $false.

Thanks.

This is what I want: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.contenttype.hidden.aspx

0

Per my test in my SharePoint online environment, I add the content type to the list in the subsite by the PnPPowerShell Add-PnPContentTypeToList, it will show when clicking on new button. The content type “item1” has been created in the site content type.

My PnP code as below:

$siteUrl="https://tenantname.sharepoint.com/sites/site1/t3"
Connect-PnPOnline -url $siteUrl
Add-PnPContentTypeToList -List "list1" -ContentType "item1"

enter image description here

enter image description here And you also could add content type to list by PowerShell script in the article below.

Add content type to an SharePoint Online list.

http://www.sharepointfire.com/2016/01/add-content-type-sharepoint-online-list-powershell/

2
-1

First you need to Load the list object and then Content Type within the list. I have tried below code and it is working for me.

http://codesharepoint.com/csom/set-list-content-type-read-only-in-sharepoint-using-csom

In the code, instead of ReadOnly = true attribute, you can pass Hidden = false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.