Answered by:
Set "Visible on New Button" for Content Type Using Powershell

Question
-
I've created the following the following code to create a new content type called Expense Report and added it to a Shared Document library on the HTTP://SP2010-WFE1:100 site. I haven't yet figured out had to make the content type visible or set it as the default type using Powershell. Any ideas?
$SPWeb100 = Get-SPWeb "HTTP://SP2010-WFE1:100"
$ContentTYpe = New-Object Microsoft.Sharepoint.ContentType -ArgumentList @($SPWeb100.ContentTypes["Document"],$SPWeb100.ContentTypes,"Expense Report")
$Group = $ContentType.Group = "Finance Content Types"
$ContentTypeCollection = $SPWeb100.ContentTypes
$ContentTypeCollection.Add($ContentType)
$List = $SPWeb100.Lists["Shared Documents"]
$ContentType = $SPWeb100.ContentTypes["Expense Report"]
$List.ContentTypes.Add($ContentType)
Joe
Sunday, August 21, 2011 7:32 PM
Answers
-
To order the Content Types, try this code
SharePoint Solution Architect, Developer- Marked as answer by Rock Wang– MSFT Friday, September 2, 2011 8:08 AM
Wednesday, August 24, 2011 5:13 PM
All replies
-
You should check that Content Types are enabled (Advances Settings > Allow management of content types? ).
Most likely you are just missing the list update() method.Here is my version:
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$SPWeb100 = Get-SPWeb "http://sp001/sites/Team1"
$ContentType = New-Object Microsoft.SharePoint.SPContentType -ArgumentList @($SPWeb100.ContentTypes["Document"],$SPWeb100.ContentTypes,"Expense Report")
$SPWeb100.ContentTypes.Add($ContentType)
$ContentType.Update()$List = $SPWeb100.Lists["Shared Documents"]
$List.ContentTypesEnabled = $true
if ($List.IsContentTypeAllowed($ContentType))
{
$listCT = $List.ContentTypes.Add($ContentType)
$List.Update()
write-host "Allowed"
} else {
write-host "Not Allowed"
}write-host "Done"
SharePoint Solution Architect, DeveloperWednesday, August 24, 2011 6:23 AM -
I appreciate the assist but I'm able to create and add the content type to a list without issue. What I'm trying to do is set the contenttype as visible when a user clicks on "New Document" and make it the "Default" document. I had already configured "Allow Management of ContentTypes" manually and can see the contenttype there. As long as I use the GUI to set "Visible on New Button" then the following code works to control it's availability on "New Document"
$List = $SPWeb100.Lists["Shared Documents"]
$list.Contenttypes["Expense Report"].Hidden=$False
$list.ContentTypes["Expense Report"].Update()
$list.Update()
$web.Update()
Weird thing is that if I choose Hidden=$True it's no longer visible as a "New Document" but if you view Library Settings - Content Types it still has it checked to be visible even though it's no longer available under "New Document". I've tested Hidden true\false values several time and they work but if I use the GUI to uncheck the option to make it visible then changing Hidden to False\true has no affect anymore...
Wednesday, August 24, 2011 3:47 PM -
To order the Content Types, try this code
SharePoint Solution Architect, Developer- Marked as answer by Rock Wang– MSFT Friday, September 2, 2011 8:08 AM
Wednesday, August 24, 2011 5:13 PM -
I found that site when I was doing my initial google search but I'm not familiar with executing that kind of code. I also have the pressing need to do this via Powershell.Wednesday, August 24, 2011 7:54 PM
-
Powershell is simply a host for this code. I'll try to rewrite it for you.
SharePoint Solution Architect, DeveloperWednesday, August 24, 2011 9:20 PM -
I'd appreciate any assist...Thanks MossDev.....
Friday, August 26, 2011 3:05 PM