Recently a customer asked us to rename several content types to conform to the company's new name. Several sources on the internet claim renaming content types is undesirable, however since it's supported through the SharePoint UI and we don't have any custom code referencing content types by name, we decided this would be ok.
Renaming a content type using PowerShell is pretty straight forward.
$web = Get-SPWeb http://intranet $oldName = "SomeContentType" $newName = "MyUpdatedContentType" $ct = $web.ContentTypes[$oldName] if ($ct -ne $null) { $ct.Name = $newName $ct.Update($true) }
This works fine for sites created in the English language. Unfortunately, our customer's portal was created as a Dutch site collection. Since updating a web title in such a scenario requires an additional step, we figured this might be the case here as well and added:
$ct.NameResource.SetValueForUICulture("nl-NL", $newName)
This turned to not be the solution. The most interesting past is, the update seemingly works fine. Even fetching the content type in a new PowerShell window shows the update. A clue to there being something wrong is in you having to retrieve the content type using the old name. The value in the array operator does not match the value either in the Name or the NameResource propery. When you check the UI you'll see the name was not actually updated.
Scanning the properties, we noticed the SchemaXml was still listing the old value in the Name attribute. SchemaXml is read-only and can't be updated, but SchemaXmlWithResourceTokens holds the same data and can be edited. Changing the script to update this value solved our problem.
$web = Get-SPWeb http://intranet $oldName = "SomeContentType" $ct = $web.ContentTypes[$oldName] if ($ct -ne $null) { $ct.SchemaXmlWithResourceTokens = $ct.SchemaXmlWithResourceTokens.Replace($oldName, $newName) $ct.Update($true) }
The name of a content type is not pushed to inheriting list content types, not even when you pass the parameter to SPContentType.Update(bool). So we altered the script to loop all the webs and lists to fix the content type. The solution of updating SchemaXmlWithResourceTokens does not work on list content types however, since the SchemaXmlWithResourceTokens is not actually used for list content types. Updating the Name and NameResource properties still does not do anything, so we are currently not able to update the list content types using PowerShell.