Import CSV file into Sharepoint list

You are here:
Table of contents

You can import easily a CSV file in your SharePoint List. If you have a file with special characters like french ones (éàè) you should save your file as CSV UTF-8 format.

You have to first load a module in your PowerShell Session (which you open as admin as usual)

Install-Module SharePointPnPPowerShellOnline

If you connect to your Sharepoint you can test it with (after Connect-PnPOnline)

Get-PnPlist

For the correct field name from sharepoint you have to edit the column and than look in the URL how it is written

https://xy.com/site01/_layouts/15/FldEdit.aspx?List=%7BDC358694-4BDB-4369-BA40-F8CB09535F10%7D&Field=Full_x0020_Name

In the URL you will find Field= at the end of it and what is written behind is the field name you have to take in the script (Here in the example: Full_x0020_Name)

Now you can execute the full script (see below)

Script:

$credentials = Get-Credential -Message "Please Enter SharePoint Online credentials"
$Site="https://xy.com/site01/"
$TestData = Import-CSV "C:\scripts\testutf8.csv"
Connect-PnPOnline -Url $Site -Credentials $credentials

foreach ($Record in $TestData){
Add-PnPListItem -List "Name of the list" -Values @{
"Title"= $Record.'Shortcut';
"Full_x0020_Name"= $Record.'Full Name';
}}

The Records are defined with SharePointColumnName = $Record.’ColumnNameInCSVFile’

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.