Create multiple list items with a CSV file using Invoke-PnPRestMethod
Did you know that there’s also a PnP PowerShell command that will use a REST request? Meaning we’ve got a different syntax, (sometimes) better performance, but the same results.
In this post, we’ll create items in a SharePoint Online list using the Invoke-PnPSPRestMethod by importing a CSV file. Let’s go! 🚀
Nothing specific in the .csv file compared to other methods of creating items. The difference will only rely on the command parameters. For this example, I just have three (3) columns/headers in my list:
The beginning will look similar to what we (admins) are used to with PowerShell.
We connect to the target site (or admin center if multiple sites to loop through) using
Connect-PnPOnline, import our
.csv file, and then we create a
foreach loop to go through all the rows in the file.
Here, we’ll directly create a hashtable referencing our column headers & items inside the loop, store that in a variable so we can then use this variable in the
By using this cmdlet, we need to specify the method we’d like our script to action:
We also need to grab our list:
Here’s what it’d look like:
Invoke-PnPSPRestMethodis inside the loop, like any other command.
Thanks for reading! 🙂