Populate a SharePoint Online list using PowerShell

Learn how to populate a SharePoint Online list using PowerShell and PnP Tools

Lets take a CSV file and use that to populate an Online SharePoint List using Powershell with the PnP Powershell tools. Follow the steps below to get started.


If you don't have them installed you will need to install the PnP PowerShell Tools for SharePoint. You can install them easily enough by launching PowerShell as an admin and running the below command.

Install-Module SharePointPnPPowerShellOnline

You can read more about PnP SharePoint Cmdlets here.


1. Setup your SharePoint List and columns

You will need to have your SharePoint list and the columns that you want to populate with data in place. I recommend not using spaces in the names of your columns because when you are entering the columns in PowerShell you have to use the internal name of the column in SharePoint. You can always change the display name of the column later in SharePoint.

2. Get your data ready

It is very easy to work with CSVs and PowerShell I will be using a small CSV file that contains a few items and using a few lines of PowerShell we will iterate through the items in the CSV and add them to the SharePoint List

3. PowerShell

Now that we are all setup we can launch PowerShell and run through the commands below to update our SharePoint list.

  1. Path to the location of your CSV file and import it to a variable using the below command.

$items = import-csv .\[nameofyour].csv

(Replace the [] and text inside with your filename)

Now that the items are imported into the PowerShell variable you can enter $items in PowerShell and get a result like below depending on your CSV file.

2. We need to run the command below to connect our PowerShell session to SharePoint Online. You will need the URL to point to a site where the list you want to populate lives. After running the below command you will be prompted for credentials to connect to the site.

connect-PnPOnline -url https://[yoursite].sharepoint.com/[site]

3. Once you are successfully connect you can run the below command to view all the lists in the site you are connected to.

Get-PnPList

4.  Run the command below to start the import into your SharePoint List

And that is all there is to it, but that is only scratching the surface of what the PnP tools and PowerShell can do for you in SharePoint Online.