SharePoint Online: Set Default Value for a List Column using PowerShell

Requirement: SharePoint Online Set Column default value Settings

How to Set Column default value Settings in SharePoint Online?

When you create a SharePoint list, you specify the type of data stored in each column. However, what if you want to set a default value for a column? Maybe you want to ensure that a particular value is automatically populated in your column whenever a new item is added. This article will show you how to set a default value for a column in the SharePoint Online list.

To preset a default value for a field in the SharePoint Online list,

  • Go to the List Settings >> Under “Columns”, Pick the field by clicking on its title
  •  Under “Default Value” section, you can specify the default value for the field, so that it gets populated automatically without user input.
    powershell to set sharepoint online column default value settings

You can also specify the default value for a column at the time of creation!

Configure Default Column Value using PowerShell CSOM

Here is how to set a default value for a column in the SharePoint Online list using PowerShell:

#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 to set default value of a field
Function Set-SPOFieldDefaultValue($SiteURL, $ListName, $FieldInternalName, $DefaultValue)
{
    Try { 
        #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 Field
        $Field = $List.Fields.GetByInternalNameOrTitle($FieldInternalName)
        $Field.DefaultValue = $DefaultValue
        $Field.Update()
        $Ctx.ExecuteQuery()
 
        Write-host -f Green "Default Value set for Field Successfully!"
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}
#Set parameter values
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Documents"
$FieldInternalName = "Classification" #Internal Name
$DefaultValue = "Invoice; Proposal; Quotation"

Set-SPOFieldDefaultValue -SiteURL $SiteURL -ListName $ListName -FieldInternalName $FieldInternalName -DefaultValue $DefaultValue

Similarly, you can set the Date column’s default value to Today’s date as:

Set-SPOFieldDefaultValue -SiteURL "https://Crescent.sharepoint.com" -ListName "Tasks" -FieldInternalName "DueDate" -DefaultValue "[Today]"

SharePoint Online: Column Default Value Settings using PnP PowerShell

PnP PowerShell way to set the default value for SharePoint Online list column:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Team Documents"
$ColumnName = "Classification" #Internal Name
$DefaultValue = "Invoice; Proposal; Quotation"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Set Default Value for the field
Set-PnPField -Identity $ColumnName -List $ListName -Values @{DefaultValue=$DefaultValue}

and the result:

sharepoint online column default value settings

You can also use the Set-PnPDefaultColumnValues cmdlet to set the default value for a column in the list.

Set-PnPDefaultColumnValues -List Documents -Field TaxKeyword -Value "Crescent|Projects|InfraBuild"

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!

3 thoughts on “SharePoint Online: Set Default Value for a List Column using PowerShell

  • Thanks for this. This shows how to set the default value or a column, but how do you set the column default value settings per folder? I am looking for a way to automate this rather than set for thousands of folders in a document library.

    Reply
  • $FieldInternalName, $DefaultValue are not used in your script, It appears to be missing something in the function Function Set-SPOFieldDefaultValue.

    Reply

Leave a Reply