Add item to SharePoint list using PowerShell

Add item to SharePoint list using PowerShell
SharePoint deveopment training course

This PowerShell SharePoint tutorial, explains how to add an item to a SharePoint list using PowerShell. The PowerShell code will work for SharePoint 2013 or SharePoint 2016 list.

The below PowerShell code will not work for SharePoint Online list. To insert an item to SharePoint Online list, you can check Insert/Add item to SharePoint Online list using PowerShell.

Add item to SharePoint List using PowerShell

Below is the PowerShell code, which will add or insert an item to SharePoint list using PowerShell.

$site = new-object Microsoft.SharePoint.SPSite(“http://site URL”)
$web = $site.rootweb
$list = $web.Lists[“ListName”]
$newitem = $list.items.Add()
$newitem[“Column Name1”]= “Column value”;
$newitem[“Column Name2”]= “Column value”;
$newitem.update()
$web.Dispose()
$site.Dispose()

Example: Add item to SharePoint 2016 list using PowerShell

Now, we will see an example of how to add an item to a SharePoint 2013/2016 list using PowerShell.

For this example, I have created a simple SharePoint custom list which has fields like:

  • Title (Single line of text)
  • Email ID (Single line of text)
  • Contact Number (Single line of text)
  • Courses (Choice Column)
  • UserComments (Multiline text)

And the SharePoint list looks like below:

Add item to SharePoint 2016 list using PowerShell

Below is the PowerShell command to insert an item to SharePoint list.

Here make sure you can use the internal column names while adding items to the list. Get SharePoint internal names of fields in SharePoint.

Just put the below code in PowerShell ISE and run the command.

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

$webURL = "http://mypc:29024/sites/SPTraining/"
$listName = "MyTrainingList"
$web = Get-SPWeb $webURL
$list = $web.Lists[$listName]
$newItem = $list.Items.Add()
$newItem["Title"] = "Bijay"
$newItem["Email_x0020_ID"] = "youremail@yourdomain.com"
$newItem["Contact_x0020_Number"] = "123455666"
$newItem["Courses"] = $newItem.Fields["Courses"].GetFieldValue("SharePoint Developer");
$newItem["UserComments"] = "I am interested for sharepoint training. please contact me."
$newItem.Update()

Once you execute the PowerShell command, the item will be added to the SharePoint list.

You may like following PowerShell SharePoint tutorials:

Hope this SharePoint tutorial helps to insert an item to SharePoint 2010/2013/2016/2019 list using PowerShell.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →