kwizcom banner advertisement

SharePoint Online: Rename a Column using PowerShell

When we create a new list or library in SharePoint/SharePoint Online, "Title" column gets created automatically. SharePoint doesn't allow us to delete this title column. However, we can change the "title" column name to something relevant such as "Project Name" in "Projects" List.

How to Rename a List Column in SharePoint Online?
Here is how to rename a List column in SharePoint Online:
  • Navigate to your target SharePoint online list >> Go to List settings page.
  • Pick any column such as "Title" from "Columns" section. You'll get Edit Column page.
  • Now you can rename the field at "Column Name" and Hit "OK" button to save your changes.
    powershell to rename column in sharepoint online

PowerShell to Rename SharePoint Online List Columns:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Rename-ListColumn()
{
  param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ColumnName,
        [Parameter(Mandatory=$true)] [String[]] $NewName
    )

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $Ctx.Load($List)
        $Ctx.ExecuteQuery()

        #Get the column to rename
        $Field = $List.Fields.GetByInternalNameOrTitle($ColumnName)
        $Field.Title = $NewName
        $Field.Update()
        $Ctx.ExecuteQuery()
            
        Write-Host "Column Name Changed successfully!" -ForegroundColor Green

    }
    Catch {
        write-host -f Red "Error Renaming Column!" $_.Exception.Message
    } 
}

#Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListName="Projects"
$ColumnName="Titles"
$NewName="Project Title"

#Call the function to rename column
Rename-ListColumn -SiteURL $SiteURL -ListName $ListName -ColumnName $ColumnName -NewName $NewName

Renaming columns from SharePoint UI and programmatically using PowerShell and C# is explained in my another articles:
SharePoint Online: Rename a Column using PowerShell SharePoint Online: Rename a Column using PowerShell Reviewed by Salaudeen Rajack on August 03, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.