How to Add Calculated Column to SharePoint List using PowerShell?

Requirement: Add new calculated field to SharePoint list programmatically using PowerShell script.

PowerShell to add a calculated column in SharePoint list or library:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebURL="http://projects.crescent.com"
$ListName="Proposal Documents"
$CalculatedColumnName="Created Month-Year"

#Get the Web
$web = Get-SPWeb $WebURL
 
#Get the List
$list = $web.Lists.TryGetList($ListName)
 
#Add new calculated column
$list.Fields.Add($CalculatedColumnName, "Calculated", $false)

#Get the column
$CalculatedCol = $List.Fields.GetField($CalculatedColumnName)
#Set Formula for calculated column 
$CalculatedCol.Formula='=TEXT(Created,"mmm-YYYY")'
$CalculatedCol.OutputType="Text"
$CalculatedCol.Update()
  
$web.Dispose() 

Script in action: Create calculated column in SharePoint 2013 using PowerShell

create calculated column in sharepoint 2013 using powershell

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!

One thought on “How to Add Calculated Column to SharePoint List using PowerShell?

  • February 1, 2016 at 5:54 AM

    Good work mate …

    Reply

Leave a Reply