top of page
Writer's pictureVijai Anand Ramalingam

Validation Settings for SharePoint list using PowerShell

In this article we will be seeing about the validation settings for SharePoint list using PowerShell.

Go to List => List Settings => General Settings => Validation Settings.


















We can add the formula to validate and give some error message.

I have a column "Years of experience" and I am going to add the validation formula as shown in the following












Using C#:

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Microsoft.SharePoint;

  6. namespace ValidationSettings

  7. {

  8. class Program   

  9. {

  10. static void Main(string[] args)       

  11. {

  12. using (SPSite site = new SPSite("http://serverName:1111/"))           

  13. {

  14. using (SPWeb web = site.RootWeb)               

  15. {                 

  16. SPList list=web.Lists["cl"];                   

  17. list.ValidationFormula = "=AND([Years of Experience]>3,[Years of Experience]<6)";                   

  18. list.ValidationMessage = "Years of experience must be between 3-6 years";                   

  19. list.Update();               

  20. }           

  21. }       

  22. }   

  23. }

  24. }

Using PowerShell:

  1. $site=Get-SPSite "http://serverName:1111/"

  2. $web=$site.RootWeb

  3. $list=$web.Lists["cl"];

  4. $list.ValidationFormula = "=AND([Years of Experience]>3,[Years of Experience]<6)"

  5. $list.ValidationMessage = "Years of exxperience must be between 3-6 years"

  6. $list.Update()

List Validation:


0 comments

Comments


bottom of page