In Focus

Creating SharePoint List Item Using PnP PowerShell

In this blog, we will see how to create SharePoint list items using PnP Powershell.

PnP provisioning is a community-driven platform that enables fast development of components that define your application infrastructure & the content to some extent. We use CSOM and can work against both SharePoint Online and SharePoint On-Premises. Let’s see how to do the Create list Item using PNP.

Prerequisite

Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.

Connect to Site

Connect to SharePoint site using Connect-PnPOnline cmdlet. The required parameters are,

  • -Url - The SharePoint site url (Eg: https://hubflysoft.sharepoint.com/sites/Hubfly)

The following code snippet helps to connect SharePoint sites.

  1. $siteurl="https://<tenant-name>.sharepoint.com"  
  2. Connect-PnPOnline -Url $siteurl  
SharePoint

To Create a list Item,

The list item can be created by “Add-PnPListItem” cmdlet in a SharePoint site.

The required parameters are,

  • -List - The ID, Title, or Url of the list.

  • -Values - Use the internal names of the fields when specifying field names.

    • Single line of text: -Values @{"Title" = "Title New"}

The following code snippet helps to create SharePoint List item

  1. Add-PnPListItem-List "HubflyTeam" -Values @{"Title"="Hubfly";"NameHF"="Ravishankar";"AgeHF"="21";"RoleHF"="Developer"}  
SharePoint

Thus, you have learned how to create list items programmatically SharePoint site. PnP PowerShell is supported by SharePoint Online. The operations mentioned above, are tested on SharePoint Online environments. Feel free to fill up the comment box below, if you need any assistance.