How to Make a Field Required in SharePoint List using PowerShell?

Requirement: Make a Field Required in SharePoint Online List.

How to Set a List Field Required in SharePoint?

A required field in SharePoint Online is a column that users must fill out when creating or editing an item. Required fields are a way to ensure that certain information is always captured and that the data entered into the list or library is consistent and complete. Users cannot save an item until they have entered a value for a required field. In this article, we will explore how to set a site column to either optional or required using list settings and PowerShell script.

To make a field required in SharePoint, or to remove the required field (to make it non-mandatory) in the SharePoint list, follow these steps:

  1. Go to List Settings >> Pick the Field by clicking on its “Title” under the “Columns” Section.
  2. Set “Yes” for “Require that this column contains information”.
  3. Click “OK” to save changes. This makes the field required. 
    sharepoint powershell set field required

PowerShell to Set a Field Required in SharePoint Online List:

Do you want to make a field required in a SharePoint list using PowerShell? This can be done by setting the Required Property of the field to $true. In this blog post, we will show you how to do this. We will also provide a script that you can use to make all fields in a SharePoint list required. Happy scripting!

Here is the PowerShell to set a column as “required”:

#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 parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName="Projects"
$FieldName="StartDate"

#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($FieldName)
$Field.Required = $True
$Field.Update()
$Ctx.ExecuteQuery()

Write-host "Field 'Required' Settings Updated!"

This makes the field required in SharePoint. Similarly, To remove the required field setting for multiple fields in the SharePoint list, use:

#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName="Projects"
#Set Field Internal Names to make required or disable required
$FieldNames=@("StartDate","ProjectID","Category","Budget")

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

#Iterate through each field given
ForEach($FieldName in $FieldNames)
{
    #Get the Field
    $Field = $List.Fields.GetByInternalNameOrTitle($FieldName)
    #disable "required" setting for the field
    $Field.Required = $False
    $Field.Update()
    $Ctx.ExecuteQuery()
    Write-host "Field '$FieldName' Required Settings Updated!"
}

PnP PowerShell to Set a List Column Required in SharePoint Online

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

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
    #Get the Field from List
    $Field = Get-PnPField -List $ListName -Identity $FieldName -ErrorAction Stop

    #Set the Field Required
    $Field.Required = $True 
    $Field.Update() 
    $Field.Context.ExecuteQuery() 

    Write-host -f Green "Field '$FieldName' Set to Mandatory!"
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

How about setting all columns required? Use the Set-PnPField cmdlet!

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/PMO"
$ListName = "Projects"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get all fields from the list
Get-PnPField -List $ListName | Where { $_.Required -eq $False -and $_.Title -ne "Name" -and $_.ReadOnlyField -eq $false -and `
    $_.Hidden -eq $false -and $_.InternalName -ne "ContentType" -and $_.InternalName -ne "Attachments"} | Set-PnPField -Values @{Required=$True}

Similarly, you can remove the required flag for all fields in SharePoint Online using the following:

Get-PnPField -List $ListName | Where { $_.Required -eq $True -and $_.Title -ne "Name" -and $_.ReadOnlyField -eq $false -and $_.Hidden -eq $false -and $_.InternalName -ne  "ContentType" -and $_.InternalName -ne  "Attachments"} | Set-PnPField -Values @{Required=$False}

Disable Required Field in SharePoint On-Premises:

If you need to remove the required flag for a field in the SharePoint list, use this PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
#Set Variables
$SiteURL="https://intranet.crescent.com"
$ListName="Projects"
$FieldName="StartDate"
 
#Get Web, List and Field Objects
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists[$ListName]
$Field = $List.Fields[$FieldName]

#Set Required to False
$Field.Required = $False
$Field.Update()
Write-host "Field Required Setting updated!"

This removes the required field in the SharePoint list (makes the field non-mandatory).

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!

2 thoughts on “How to Make a Field Required in SharePoint List using PowerShell?

  • After a New Item form is already in use, can you go back and change certain fields to be required going forward without impacted the forms that were already completed previously?

    Reply
  • This doesn’t seem to be available for lookup columns? We had lookup columns required since Office 365 was released. Today I noticed that those fields are no longer required. Is that a change?

    Reply

Leave a Reply

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