0

I want to rename a column which is associated to Content Type i used the following to update all the columns which contains the column in the list but forgot to update the column name in the content type and not sure how to approach it

$SiteURL = "http://pnpdemo" $OldColumnName ="Target Folder" $NewColumnName ="New Target Folder"

$site = Get-SPSite $SiteURL foreach ($web in $site.AllWebs) {

$ListsToProcess= @()

$Lists = $web.Lists

 foreach ($list in $lists)
 {

     foreach ($column in $list.Fields)
     {

         if ($column.Title -eq $OldColumnName)
         {
               Write-Host "Found the Column in list: " $list.Title " at "$web.Url
               #Send it to an Array
               $ListsToProcess+=$List
         }
     }
 }

foreach ($list in $ListsToProcess) {

     $column = $list.fields | where {$_.Title -eq $OldColumnName}


     $column.Title = $NewColumnName
     $column.Update()

} $web.Dispose() } $site.Dispose()

2 Answers 2

0

You can access "Content Types" option in "Site Settings" page, identify the content type with that column and modify it manually. It will be replicated across all lists.

4
  • Yes but need power shell as l have quite a few changes to be made
    – John Smith
    Aug 14, 2019 at 15:02
  • You can obtain the Content Types defined in a web using the "ContentTypes" property. Working with their fileds should be as easy as you've done with lists. Something like $web.ContentTypes I assume you are running the script in a farm server.
    – jaloplo
    Aug 14, 2019 at 15:07
  • Yes running on farm server, can you show me with powershell sample
    – John Smith
    Aug 14, 2019 at 15:14
  • Modify your script to get all content types from your web the way I showed you on my previous comment.
    – jaloplo
    Aug 14, 2019 at 15:47
0

If you want to rename the site column in Content Type, we can use PowerShell below to achieve it.

$SiteURL = "http://test"
$OldColumnName ="Target Folder"
$NewColumnName ="New Target Folder"

$site = Get-SPSite $SiteURL
foreach ($web in $site.AllWebs) {

    $field=$web.Fields[$OldColumnName]
    if($field){      
        $field.Title=$NewColumnName
        $field.update()
    }   
    $web.Dispose()
}
$site.Dispose()
1
  • When l go to "site settings>Site Content Type>My Content Type" (List of columns) it hasn't updated it in there but when l click on the old name column then "Edit site Column" its updated the name there, just also need it updating in "site settings>Site Content Type>My Content Type"
    – John Smith
    Sep 5, 2019 at 17:20

Your Answer

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

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