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:

  1. Navigate to the SharePoint Online list or library where you want to edit a column.
  2. Go to the list or library settings page from Ribbon or the Site Settings menu >> Under the Columns section, pick the column to update.
  3. 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 that changing column type is limited to specific columns based on the current column type. Furthermore, you may lose data 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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “SharePoint Online: Change List Field Settings using PowerShell

  • How to change FieldType, eg from single line of text to multiple lines?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *