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. Show 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:
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.
SharePoint Online PowerShell add list itemBelow 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 = "https://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 listThe 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 = "https://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 PowerShellWe 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. Read some SharePoint PowerShell tutorials:
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 |