简体   繁体   中英

PnP PowerShell - Upload CSV to SharePoint List

I'm looking for some help with PnP PowerShell. I have a script which takes a CSV file and uploads each row as an item to SharePoint Online (see below). My question is, how do I get the script to skip items that already exist in the SharePoint Online list? Currently the script just uploads all rows within the CSV and creates some duplicates.

#Parameters
$SiteUrl = "{site}"
$ListName = "iPhone"

$CSVPath = "C:\Users\{user}\Documents\PowerShell\Upload SharePoint items from CSV\iphoneexport.csv"



#Get the CSV file contents
$CSVData = Import-CsV -Path $CSVPath

#Connect to site
Connect-PnPOnline $SiteUrl -Interactive


#Iterate through each Row in the CSV and import data to SharePoint Online List
ForEach ($Row in $CSVData)
{
Write-Host "Adding Item $($Row.'Asset Number')"


#Add List Items - Map with Internal Names of the Fields!
Add-PnPListItem -List $ListName -Values @{"Title" = $($Row.'Asset Number');

                        "User" = $($Row.User);

};

}

I'd be grateful for any advice anyone can give.

Many thanks,

Alex.

As a workaround, you could enforce unique values for the Title column in list settings. As the below picture shows:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM