Recently, I blogged about renaming content types using PowerShell and how it gave us problems on sites not created in the en-US locale. When I was testing this, I came across a blog by Vesa "vesku" Juvonen explaining how to perform this action using CSOM. Since there is no mention of the issue I ran into, I decided to have another go at the issue.
The key to solving the issue was enabling multilingual support on the site. This may sound obvious, but keep in mind that we don't actually need multiple languages on the site; just Dutch. Also, there is no "enable multiple languages" checkbox. In order to enable this, you need select an alternative language in the language settings.
And that's it. With multilingual enabled you can use the NameResource attribute to rename content types in your site. Keep in mind that changing the name of a content type does not rename inheriting list content types and that we're only changing the labels here and not the actual name of the content type, so when retrieving the content type in code, we'll need to use the original name (or even better: use its id). Finally, the alternative languages setting is not inherited in subsites (so you need to manually set this on each subweb or use a script for this as well).
Wrapping it up, here's the script I used to rename the my content type and update the inheriting list content types.
function RenameContentType($web, $id, $newName) { $ctId = New-Object Microsoft.SharePoint.SPContentTypeId($id) $ct = $web.ContentTypes[$ctId] if ($ct -ne $null) { Write-Host ("Got ct from web: " + $ct.Name) -ForegroundColor Magenta $ct.NameResource.SetValueForUICulture("nl-NL", $newName) $ct.NameResource.SetValueForUICulture("en-US", $newName) $ct.Update() Write-Host ("Renamed ct in web: " + $web.Url) -ForeGroundColor Magenta } else { Write-Host ("ct not found in " + $web.Url) -ForegroundColor Magenta } $web.Lists | foreach { $list = $_ $listContentType = $list.ContentTypes | where { $_.Id.ToString().StartsWith($id) } if ($listContentType -ne $null) { $listContentType.NameResource.SetValueForUICulture("nl-NL", $newName) $listContentType.NameResource.SetValueForUICulture("en-US", $newName) $listContentType.Update()
Write-Host ("Renamed ct in list: " + $list.Title) -ForeGroundColor Magenta } else { Write-Host ("ct not found in list: " + $list.Title) -ForegroundColor Magenta } } } $web = Get-SPWeb "http://intranet" RenameContentType $web "0x010100B77AD27D029AF349AE1C73FC9E7C9D34" "MyUpdatedContentType"