How to Add a Column to SharePoint List using PowerShell?

Requirement: Add columns to SharePoint list using PowerShell.

PowerShell Script to Add Columns to SharePoint List:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Add-FieldToList($SiteURL,$ListName, $FieldName, $FieldType, $IsRequired)
    #Set the Error Action
    $ErrorActionPreference = "Stop"

        #Get the List
        $List = (Get-SPWeb $SiteURL).Lists.TryGetList($ListName)
        #Check if List with specific name exists
        if($List -ne $null)
                #Add columns to the List 

                #Update the List

                #Update the default view to include the new column
                $View = $List.DefaultView # OR $List.Views["All Items"]

                write-host "New Column '$FieldName' Added to the List!" -ForegroundColor Green
                write-host "Field '$FieldName' Already Exists in the List" -ForegroundColor Red
            write-host "List '$ListName' doesn't exists!" -ForegroundColor Red
     catch {
        Write-Host $_.Exception.Message -ForegroundColor Red
    finally {
        #Reset the Error Action to Default
        $ErrorActionPreference = "Continue"

$ListName = "Customer Directory"

#Add 'Name' - Single Line of Text Field
$FieldType = [Microsoft.SharePoint.SPFieldType]::Text
$IsRequired = $False
#Call the funtion to Add Field to List
Add-FieldToList $SiteURL $ListName $FieldName $FieldType $IsRequired

#Add Phone Number - Number Field
$FieldType = [Microsoft.SharePoint.SPFieldType]::Number
$FieldName="Phone Number"
$IsRequired = $False
#Call the funtion to Add Field to List
Add-FieldToList $SiteURL $ListName $FieldName $FieldType $IsRequired

#Date of Joing - Date Field
$FieldType = [Microsoft.SharePoint.SPFieldType]::DateTime
$FieldName="Date of Join"
$IsRequired = $False
#Call the funtion to Add Field to List
Add-FieldToList $SiteURL $ListName $FieldName $FieldType $IsRequired

You can also add fields to SharePoint list from their field schema. Here is how:
#Field Schemas
$NameFldSchema="<Field Type='Text' DisplayName='Name' Required='False' MaxLength='255' StaticName='Name' Name='Name' />"
$PhoneNoFldSchema="<Field Type='Number' DisplayName='Phone Number' Required='False' MaxLength='255' StaticName='PhoneNumber' Name='PhoneNumber' />"
$DOBFldSchema="<Field Type='DateTime' DisplayName='Date of Birth' Required='False' MaxLength='255' StaticName='DateOfBirth' Name='DateOfBirth' /> "
#For Field schemas, Refer:
#Add Columns to the List
$List.Fields.AddFieldAsXml($NameFldSchema, $True,[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)

While the above script is fairly simple, to add other type of fields such as choice fields, lookups, etc.  refer below posts:


  1. Hi Salaudeen

    Thanks for this script, it is appreciated.
    I just can't get it to work for a "Person or Group" column.
    I tried:
    $FieldType = [Microsoft.SharePoint.SPFieldType]::Person
    $FieldType = [Microsoft.SharePoint.SPFieldType]::PersonGroup

    Nothing seems to work.
    Thanks again

    1. Try the FieldXML Method: $FieldXml = "<Field Type='User' DisplayName='"+ $DisplayName +"' Required='"+ $Required +"' Name='"+ $Name +"'/>"

    2. Hello,

      can you explaint how to ad "FieldXML Method: $FieldXml for "Person or Group" to this script in up site?

      I´m new in powershell. I have the same problem with add Person and Group Column and set parameters fields. Thx for help.

  2. Thanks mate, all the best!


Please Login and comment to get your questions answered!

Powered by Blogger.