SharePoint Online: Change List Field Settings using PowerShell

Requirement: Update SharePoint Online List Field Settings using PowerShell

How to Edit Column Settings in SharePoint Online?

Properties of the list field, such as display name, type, or other related column settings, can be updated through the list settings page. To change column settings in a list or library, follow these steps:

  • Navigate to the SharePoint Online list or library where you want to edit a column.
  • Go to the list or library settings page either from Ribbon or from the Site Settings menu >>Under the Columns section, Pick the column to update
  • On the Edit Column page, You can make any necessary changes and click on the OK button to Save.
    SharePoint Online update List Field Settings using PowerShell

Please note, changing column type is limited within specific columns based on the current type of the column. Also, you may end up in data loss when switching between column types. E.g., When you switch from Multiple lines of text to a Single line of text, It’s limited to 255 characters.

PowerShell to Change Field Settings in SharePoint Online List:

We can also change field settings for a list in SharePoint Online using PowerShell. This can be useful if you need to make changes to a field’s properties such as the display name, required flag, default value, etc.

#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"

#Set Config Parameters
$SiteURL="https://crescent.sharepoint.com/sites/projects"
$ListName="Projects"
$FieldName="HeadCount" #Internal Name

#Get Credentials to connect
$Cred= Get-Credential

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Get the List
$List=$Ctx.Web.Lists.GetByTitle($ListName)

#Get the List Field
$Field=$List.Fields.GetByInternalNameOrTitle($FieldInternalName)
$Ctx.Load($Field)
$Ctx.ExecuteQuery()

#Set List Field Settings
$Field.Title= "Total Resources"
$Field.Description = "Number of Resources working on the Project"

#set default value
$Field.DefaultValue = "10"

$Field.EnforceUniqueValues = $False

#set field hidden
$Field.Hidden = $False

#set field required
$Field.Required = $True
$Field.FieldTypeKind = "Text"
$Field.Indexed = $False

#set field read only
#$Field.ReadOnlyField = $True

#Apply changes
$Field.Update()
$Ctx.ExecuteQuery()

Write-host "Field Settings Updated!"

PnP PowerShell to Update Field Properties in SharePoint Online List

Here is how to automate changing the field settings for a SharePoint Online list using PnP PowerShell:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Projects"
$FieldName = "ProjectStatus" #Internal Name

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
    #Set Field Properties
    Set-PnPField -List $ListName -Identity $FieldName -Values @{Required=$True;DefaultValue="Active"}    
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

Similarly, you can set any other property of the list field such as “Title” or “Description” as:

-Values @{Title="Name of the Column";Description="Updated List Description"}  

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply