Add item to list SharePoint

This PowerShell SharePoint tutorial explains, how we can insert an item to SharePoint Online list using PowerShell. We can easily add items to a SharePoint Online list using PowerShell.

Complete SharePoint Training Course Just for $199 [Just for Today]

[toc]

In this particular SharePoint PowerShell example, I have a SharePoint Online list name as Logging which has below two columns:

  • Title
  • Description

By using CSOM PowerShell we will see how can add an item to the SharePoint Online list.

To work with PowerShell SharePoint Online, you need to make sure, you have the required below client dlls.

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

SharePoint Online PowerShell add list item

Below is the PowerShell script to add an item to SharePoint Online list which you can write in Windows PowerShell ISE or also you can use Visual Studio Code to write and debug PowerShell Script.

Add-Type -Path 'E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll' Add-Type -Path 'E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll' $SiteURL = "//onlysharepoint2013.sharepoint.com/sites/Bhawana/" $ListName="Logging" $Context = New-Object Microsoft.SharePoint.Client.ClientContext[$SiteURL] $securePassword=ConvertTo-SecureString "MyPassword" -AsPlainText -Force $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials["", $securePassword] $Web = $Context.Web $List = $web.get_lists[].getByTitle[$ListName] $itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation $listItem = $list.addItem[$itemCreateInfo] $listItem.set_item['Title', 'Item Title'] $listItem.set_item['Description', 'Item Description'] $listItem.update[]; $Context.Load[$listItem] $Context.ExecuteQuery[]

Once you run the code, you can see the items will be added successfully to the SharePoint online list.

PowerShell Insert items to SharePoint Online list

PowerShell insert multiple or bulk items to SharePoint Online list

The above code will add a single item to the SharePoint Online list. But you can also add multiple items to SharePoint Online list using PowerShell CSOM.

Below is the PowerShell script.

Add-Type -Path 'E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll' Add-Type -Path 'E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll' $SiteURL = "//onlysharepoint2013.sharepoint.com/sites/Bhawana/" $ListName="Logging" $Context = New-Object Microsoft.SharePoint.Client.ClientContext[$SiteURL] $securePassword=ConvertTo-SecureString "*******" -AsPlainText -Force $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials["******@onlysharepoint2013.onmicrosoft.com", $securePassword] $Web = $Context.Web $List = $web.get_lists[].getByTitle[$ListName] for [$i=1; $i -le 10; $i++] { $itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation $listItem = $list.addItem[$itemCreateInfo] $listItem["Title"] = "Item-$[$i]" $listItem["Description"] = "Description-$[$i]" $listItem.Update[] $Context.ExecuteQuery[] }

The above PowerShell script will add 10 items to the SharePoint Online list.

PowerShell add multiple or bulk items to SharePoint Online list

Add item to SharePoint online list PnP PowerShell

We can also use PnP PowerShell to add item to SharePoint Online list.

Below is the PnP PowerShell script to add an item to the SharePoint Online list.

$SiteURL = "//onlysharepoint2013.sharepoint.com/sites/Bhawana/" $ListName ="Logging" Connect-PnPOnline -Url $SiteURL -Credentials [Get-Credential] Add-PnPListItem -List $ListName -Values @{"Title" = "Item 1"; "Description"="This is the description to add item to SharePoint Online list using PowerShell"}

Read some SharePoint PowerShell tutorials:

  • Enable or Disable List Throttling using PowerShell in SharePoint 2013
  • Bulk SharePoint Online Site Collection Creation using PowerShell
  • Delete Hidden Web Application in SharePoint 2013 using PowerShell
  • Hide Document Library or Lists using PowerShell in SharePoint 2016 or SharePoint 2013
  • Increase SharePoint Online Storage Quota using PowerShell
  • How to send email using PowerShell in Office 365
  • Exception calling ExecuteQuery with 0 argument[s]: Unable to connect to the remote server

Tags:powershell add item to list, powershell add item to list sharepoint, sharepoint online powershell add list item, add item to sharepoint list using powershell, add new item to sharepoint list using powershell, sharepoint online powershell add list item, csom powershell add list item, powershell add to sharepoint online list, Insert item to SharePoint Online list using PowerShell

I hope this article will be helpful to insert items to list using PowerShell in SharePoint Online.

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 Hope here I can contribute and share my knowledge to the fullest. As I believe There is no wealth like knowledge and no poverty like ignorance

Video liên quan

Chủ Đề