5

I have a list where I am trying to edit the display name of some internal SharePoint fields, i.e. the "Title"-field.

I am using this code which runs, and gives no error, but it doesn't edit the display name of the column in the list.

$web = Get-SPWeb -Identity "url"
$list = $web.Lists["listname"]
$column = $list.Fields["Title"]
$column.Title = "Edited name"
$column.Update()

If I use the GUI it works, but not by script - I need to make it work with the script. Any ideas what I am doing wrong here?

4 Answers 4

5

I found a way to fix this. My code, and others provided here, do not work. The schema xml has to be edited, i.e. like this:

$w = get-spweb "http://pub.pdogs.local"
$l = $w.Lists["Simple List"]
$f = $l.Fields.GetFieldByInternalName("MyCustomColumn")
if ($f -ne $null) {
    "$($f.SchemaXml)`n"
    $f.Title = "Changed via code 2"
    $xml = $f.SchemaXml
    $f.Title
    $f.TitleResource.Value
    "`n$xml`n"
    if ($xml -match "\s+DisplayName\s?=\s?`"([^`"]+)`"") {
        if ($matches[1] -ne $f.Title) {
            $xml = $xml -replace $matches[0], " DisplayName=`"$($f.Title)`""
            $f.SchemaXml = $xml
            $xml
        }
    }
}
$f.Update()
$w.Dispose()

Here is a full explenation for those interested:

https://platinumdogs.me/2014/01/13/setting-sharepoint-2013-columnfield-title-not-working-correctly/

1
$column = $list.Fields["Internal Name"]

You should create the column object using internal name and not using title.

1

Try this code:

$web = Get-SPWeb -Identity SiteURL 
$list = $web.Lists["List Title"] 
$fld = $list.Fields.GetFieldByInternalName("Title") 
$fld.Title = "Edited Title" 
$fld.Update()
6
  • Thanks for the code, but this didn't work for me. Does it work for you?
    – Ilyas
    Sep 6, 2016 at 8:29
  • yes.. i have tested it first in my environment..
    – SID
    Sep 6, 2016 at 8:51
  • I inspected with SharePoint manager, and the column was edited there. I then inspected the schema xml, there the display name was the old one, so I don't see it in the GUI. Maybe some update issues here. Butr very strange, indeed.
    – Ilyas
    Sep 6, 2016 at 8:54
  • 2
    Dear @SID Did you consider that my edit is not useful for your answer ? I found the code format was not correct so I did changes ! Sep 6, 2016 at 10:15
  • Yes your edit is not useful.. Right answer is more important.. And dear if your edit is useful then i never raised question on your edit..
    – SID
    Sep 6, 2016 at 11:08
1

There is problem with your script:

$web = Get-SPWeb -Identity "http://devssite:1000/testSite/"
$list = $web.Lists["testList"]
$column = $list.Fields["Title"]
$column.Title = "Edited name"
$column.Update()

When you do $column = $list.Fields["Title"] its returning nothing. Its not even throwing error. You can test by printing $column.Title right after that.

Working and test solution:

$web = Get-SPWeb -Identity "http://devssite:1000/testSite/"
$list = $web.Lists["testList"]
$column = $list.Fields.GetFieldByInternalName("Title")
$column.Title = "Edited name"
$column.Update()

You can see after $column = $list.Fields.GetFieldByInternalName("Title") this statement, if you evaluate $column.Title It will give you the title of the column.

This is also affecting the GUI. I just refreshed the screen after running powershell.

1
  • Hi. I tried that also before posting. This did not work for me. I had to do some changes in the schema xml to make it work.
    – Ilyas
    Sep 6, 2016 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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